From be2d09ca038e9b33129ef48aaa72654a58eb9a90 Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Wed, 17 May 2023 11:58:23 +0200 Subject: [PATCH] Fix latency issues in search --- stockingly-frontend/src/views/Home.vue | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/stockingly-frontend/src/views/Home.vue b/stockingly-frontend/src/views/Home.vue index 680993b..4e2132c 100644 --- a/stockingly-frontend/src/views/Home.vue +++ b/stockingly-frontend/src/views/Home.vue @@ -100,19 +100,22 @@ const selected = reactive([]); const searchText = ref(""); let fuse: Fuse | 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;