From 0ec265b1fbaf2e623e6708feca4f11211a23931a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Tue, 2 Mar 2021 16:48:04 +0100 Subject: [PATCH] Use proper debounce on the sharing input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/components/board/SharingTabSidebar.vue | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/board/SharingTabSidebar.vue b/src/components/board/SharingTabSidebar.vue index 7fbf446cb..c8648643e 100644 --- a/src/components/board/SharingTabSidebar.vue +++ b/src/components/board/SharingTabSidebar.vue @@ -73,6 +73,7 @@ import { CollectionList } from 'nextcloud-vue-collections' import { mapGetters, mapState } from 'vuex' import { getCurrentUser } from '@nextcloud/auth' import { showError } from '@nextcloud/dialogs' +import { debounce } from 'lodash' export default { name: 'SharingTabSidebar', @@ -148,18 +149,13 @@ export default { this.asyncFind('') }, methods: { + debouncedFind: debounce(async function(query) { + this.isSearching = true + await this.$store.dispatch('loadSharees', query) + this.isSearching = false + }, 300), async asyncFind(query) { - // manual debounce to handle async searching more easily and have more control over the loading state - const timestamp = (new Date()).getTime() - if (!this.isSearching || timestamp > this.isSearching + 300) { - this.isSearching = timestamp - await this.$store.dispatch('loadSharees', query) - - // only reset searching flag if the most recent search finished - if (this.isSearching === timestamp) { - this.isSearching = false - } - } + await this.debouncedFind(query) }, async clickAddAcl() { this.addAclForAPI = {