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("");
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;