aboutsummaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authorTerry Truong <terry06890@gmail.com>2022-05-04 20:21:40 +1000
committerTerry Truong <terry06890@gmail.com>2022-05-04 20:21:46 +1000
commit94be9ac1974b3a6e81cdc05379c34b5038e0bd63 (patch)
treee9bf571e59d360924361226339840d7b63c64250 /src/components
parent76a1a2318f2c7378e09aacc38e1727e20c41a3b0 (diff)
Prevent search-suggestion-request delay for initial inputs
Diffstat (limited to 'src/components')
-rw-r--r--src/components/SearchModal.vue10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/components/SearchModal.vue b/src/components/SearchModal.vue
index 9cc3a29..5f5320d 100644
--- a/src/components/SearchModal.vue
+++ b/src/components/SearchModal.vue
@@ -89,14 +89,17 @@ export default defineComponent({
this.focusedSuggIdx = null;
return;
}
- // Clear any pending request
- clearTimeout(this.pendingSearchSuggReq);
// Ask server for search-suggestions
let url = new URL(window.location.href);
url.pathname = '/data/search';
url.search = '?name=' + encodeURIComponent(input.value);
this.lastSuggReqId += 1;
let suggsId = this.lastSuggReqId;
+ let reqDelay = 0;
+ if (this.pendingSearchSuggReq != 0){
+ clearTimeout(this.pendingSearchSuggReq);
+ reqDelay = 300;
+ }
this.pendingSearchSuggReq = setTimeout(() =>
fetch(url.toString())
.then(response => response.json())
@@ -105,9 +108,10 @@ export default defineComponent({
this.searchSuggs = results[0];
this.searchHasMoreSuggs = results[1];
this.focusedSuggIdx = null;
+ this.pendingSearchSuggReq = 0;
}
}),
- 300
+ reqDelay
);
},
onDownKey(){