Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Add Debounce to filter selection (#2104)

Antond2926b7f4dd6
diff --git a/src/components/VFilters/VSearchGridFilter.vue b/src/components/VFilters/VSearchGridFilter.vue
index 319ac99dc..e5f15af28 100644
--- a/src/components/VFilters/VSearchGridFilter.vue
+++ b/src/components/VFilters/VSearchGridFilter.vue
@@ -51,10 +51,11 @@ import {
ref,
useContext,
useRouter,
- watch,
} from "@nuxtjs/composition-api"
import { kebab } from "case"
+import { watchDebounced } from "@vueuse/core"
+
import { useSearchStore } from "~/stores/search"
import { areQueriesEqual, ApiQueryParams } from "~/utils/search-query-transform"
import { Focus, focusIn, getFocusableElements } from "~/utils/focus-management"
@@ -115,13 +116,14 @@ export default defineComponent({
* This watcher fires even when the queries are equal. We update the path only
* when the queries change.
*/
- watch(
+ watchDebounced(
() => searchStore.searchQueryParams,
(newQuery: ApiQueryParams, oldQuery: ApiQueryParams) => {
if (!areQueriesEqual(newQuery, oldQuery)) {
router.push(searchStore.getSearchPath())
}
- }
+ },
+ { debounce: 800, maxWait: 5000 }
)
const focusableElements = computed(() =>
diff --git a/test/playwright/e2e/search-navigation-old.spec.ts b/test/playwright/e2e/search-navigation-old.spec.ts
index 22c75dacc..3e405cb10 100644
--- a/test/playwright/e2e/search-navigation-old.spec.ts
+++ b/test/playwright/e2e/search-navigation-old.spec.ts
@@ -24,6 +24,9 @@ test.describe("search history navigation", () => {
// Apply a filter
await page.click("#modification")
+ // There is a debounce when choosing a filter.
+ // we need to wait for the page to reload before running the test
+ await page.waitForNavigation()
// Verify the filter is applied to the URL and the checkbox is checked
// Note: Need to add that a search was actually executed with the new
diff --git a/test/playwright/e2e/search-navigation.spec.ts b/test/playwright/e2e/search-navigation.spec.ts
index fd83bff66..ee338c413 100644
--- a/test/playwright/e2e/search-navigation.spec.ts
+++ b/test/playwright/e2e/search-navigation.spec.ts
@@ -28,6 +28,9 @@ test.describe("search history navigation", () => {
// Apply a filter
await page.click("#modification")
+ // There is a debounce when choosing a filter.
+ // we need to wait for the page to reload before running the test
+ await page.waitForNavigation()
// Verify the filter is applied to the URL and the checkbox is checked
// Note: Need to add that a search was actually executed with the new