From 7e07a183fe4e7185d7363e7ef84611f6130bee15 Mon Sep 17 00:00:00 2001 From: OganM Date: Fri, 4 Oct 2024 14:08:38 -0700 Subject: [PATCH] immediate execution on enter. closes #98 --- src/components/SearchSettings.vue | 4 +++ src/views/Browser.vue | 48 +++++++++++++++++-------------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/src/components/SearchSettings.vue b/src/components/SearchSettings.vue index ec9fde5..c78e8cd 100644 --- a/src/components/SearchSettings.vue +++ b/src/components/SearchSettings.vue @@ -23,6 +23,7 @@ { + let location = browsingOptions.query ? "/q/" + encodeURIComponent(browsingOptions.query) : "/"; + // because this is debounced, it's possible that two consecutive searches are performed with the same query + // i.e. user types "brain" and obtain results, then deletes one char "brai" and add one char back to "brain" + // in less than 1s + if (location !== this.$router.currentRoute.fullPath) { + return this.$router.push(location); + } + }).catch(swallowCancellation) + .catch(err => { + // because the function is debounced, the caller might never get resulting promise and ability to handle the error + console.error("Error while searching: " + err.message + ".", err); + this.setLastError(err); + }); + }, 1000) }; }, computed: { @@ -421,28 +444,11 @@ export default { } }, methods: { + flush: function(){ + this.search.flush() + }, formatDecimal, formatPercent, - /** - * Basically a browse with a debounce when the user is actively typing a query. - * @return {Promise|undefined} initially undefined, then a promise once the function has been invoked at least once - */ - search: debounce(function(browsingOptions) { - return this.browse(browsingOptions, true).then(() => { - let location = browsingOptions.query ? "/q/" + encodeURIComponent(browsingOptions.query) : "/"; - // because this is debounced, it's possible that two consecutive searches are performed with the same query - // i.e. user types "brain" and obtain results, then deletes one char "brai" and add one char back to "brain" - // in less than 1s - if (location !== this.$router.currentRoute.fullPath) { - return this.$router.push(location); - } - }).catch(swallowCancellation) - .catch(err => { - // because the function is debounced, the caller might never get resulting promise and ability to handle the error - console.error("Error while searching: " + err.message + ".", err); - this.setLastError(err); - }); - }, 1000), browse(browsingOptions, updateEverything) { // update available annotations and number of datasets let updateDatasetsPromise = this.updateDatasets(browsingOptions.query, browsingOptions.filter, browsingOptions.offset, browsingOptions.limit, browsingOptions.sort);