From 94be9ac1974b3a6e81cdc05379c34b5038e0bd63 Mon Sep 17 00:00:00 2001
From: Terry Truong <terry06890@gmail.com>
Date: Wed, 4 May 2022 20:21:40 +1000
Subject: Prevent search-suggestion-request delay for initial inputs

---
 src/components/SearchModal.vue | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

(limited to 'src/components/SearchModal.vue')

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(){
-- 
cgit v1.2.3

