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("");
|
const searchText = ref("");
|
||||||
let fuse: Fuse<Company> | undefined = undefined;
|
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 (!fuse) return;
|
||||||
if (!searchText.value) {
|
if (searchText.value === '') {
|
||||||
filteredCompanies.value = companies.value;
|
filteredCompanies.value = companies.value;
|
||||||
|
loading.value = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
setTimeout(() => {
|
search();
|
||||||
filteredCompanies.value = fuse!.search(searchText.value).map(e => ({ ...e.item, score: e.score }))
|
|
||||||
}, 50);
|
|
||||||
}
|
}
|
||||||
}, 300))
|
});
|
||||||
|
|
||||||
const isSelected = (ticker: string) => selected.indexOf(ticker) !== -1;
|
const isSelected = (ticker: string) => selected.indexOf(ticker) !== -1;
|
||||||
|
|
||||||
|
|
Reference in a new issue