Fix latency issues in search

This commit is contained in:
Claudio Maggioni 2023-05-17 11:58:23 +02:00
parent 8bf18c9c9e
commit be2d09ca03

View file

@ -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;