From fee1f4bbd5705c24bdf72c61507ae57f9de06ee7 Mon Sep 17 00:00:00 2001 From: Spythere Date: Thu, 22 Dec 2022 01:36:38 +0100 Subject: [PATCH] =?UTF-8?q?Usprawienie=20podpowiedzi=20filtr=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/JournalView/JournalOptions.vue | 53 ++++++++----------- 1 file changed, 22 insertions(+), 31 deletions(-) diff --git a/src/components/JournalView/JournalOptions.vue b/src/components/JournalView/JournalOptions.vue index 8f4064e..9bc2449 100644 --- a/src/components/JournalView/JournalOptions.vue +++ b/src/components/JournalView/JournalOptions.vue @@ -120,8 +120,8 @@ export default defineComponent({ currentOptionsActive: { type: Boolean, - default: false - } + default: false, + }, }, data() { @@ -171,41 +171,14 @@ export default defineComponent({ if (!value || value == '') return; if (value.length < 3) return; - this.searchTimeout = setTimeout(async () => { - try { - const driverSuggestions: string[] = await ( - await axios.get(`${URLs.stacjownikAPI}/api/getDriverSuggestions?name=${value}`) - ).data; - - this.driverSuggestions = driverSuggestions; - } catch (error) { - this.driverSuggestions = []; - } - }, 1500); - - // this.loadingDriverSuggestions = true; - - // this.loadingDriverSuggestions = false; - // this.nextSearchTimestamp = Date.now() + 100; + this.startSearchTimeout('driver', value); }, async 'searchersValues.search-dispatcher'(value: string | undefined) { - clearTimeout(this.searchTimeout); - if (!value || value == '') return; if (value.length < 3) return; - this.searchTimeout = setTimeout(async () => { - try { - const dispatcherSuggestions: string[] = await ( - await axios.get(`${URLs.stacjownikAPI}/api/getDispatcherSuggestions?name=${value}`) - ).data; - - this.dispatcherSuggestions = dispatcherSuggestions; - } catch (error) { - this.dispatcherSuggestions = []; - } - }, 1500); + this.startSearchTimeout('dispatcher', value); }, }, @@ -233,6 +206,24 @@ export default defineComponent({ } }, + startSearchTimeout(type: 'driver' | 'dispatcher', value: string) { + if (this[`${type}Suggestions`].includes(value)) return; + + window.clearTimeout(this.searchTimeout); + + this.searchTimeout = setTimeout(async () => { + try { + const suggestions: string[] = await ( + await axios.get(`${URLs.stacjownikAPI}/api/get${type}Suggestions?name=${value}`) + ).data; + + this[`${type}Suggestions`] = suggestions; + } catch (error) { + this[`${type}Suggestions`] = []; + } + }, 450); + }, + // Override keyMixin function onKeyDownFunction() { this.showOptions = !this.showOptions;