Fix latency issues in search
This commit is contained in:
parent
8bf18c9c9e
commit
be2d09ca03
1 changed files with 9 additions and 6 deletions
|
@ -100,19 +100,22 @@ const selected = reactive<string[]>([]);
|
|||
const searchText = ref("");
|
||||
let fuse: Fuse<Company> | undefined = undefined;
|
||||
|
||||
watch(searchText, debounce(() => {
|
||||
const search = debounce(() => setTimeout(() => {
|
||||
filteredCompanies.value = fuse!.search(searchText.value).map(e => ({ ...e.item, score: e.score }))
|
||||
}, 800));
|
||||
|
||||
watch(searchText, () => {
|
||||
if (!fuse) return;
|
||||
if (!searchText.value) {
|
||||
if (searchText.value === '') {
|
||||
filteredCompanies.value = companies.value;
|
||||
loading.value = false;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
loading.value = true;
|
||||
setTimeout(() => {
|
||||
filteredCompanies.value = fuse!.search(searchText.value).map(e => ({ ...e.item, score: e.score }))
|
||||
}, 50);
|
||||
search();
|
||||
}
|
||||
}, 300))
|
||||
});
|
||||
|
||||
const isSelected = (ticker: string) => selected.indexOf(ticker) !== -1;
|
||||
|
||||
|
|
Reference in a new issue