From d73bafec97cd7d8eda887d21870427262befab0f Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 24 May 2023 10:56:02 +0200 Subject: [PATCH] fix(front): reset page number to 1 when search criteria changes Closes #1272 Signed-off-by: Thomas Citharel --- js/src/views/SearchView.vue | 48 ++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/js/src/views/SearchView.vue b/js/src/views/SearchView.vue index ad09e1d2..5d76def9 100644 --- a/js/src/views/SearchView.vue +++ b/js/src/views/SearchView.vue @@ -868,20 +868,6 @@ const contentType = useRouteQuery( enumTransformer(ContentType) ); -watch(contentType, (newContentType: ContentType) => { - switch (newContentType) { - case ContentType.ALL: - page.value = 1; - break; - case ContentType.EVENTS: - eventPage.value = 1; - break; - case ContentType.GROUPS: - groupPage.value = 1; - break; - } -}); - const isOnline = useRouteQuery("isOnline", false, booleanTransformer); const categoryOneOf = useRouteQuery("categoryOneOf", [], arrayTransformer); const statusOneOf = useRouteQuery( @@ -1261,6 +1247,40 @@ const boostLanguagesQuery = computed((): string[] => { return Array.from(languages); }); +// When search criteria changes, reset page number to 1 +watch( + [ + contentType, + searchDebounced, + geoHashLocation, + start, + end, + radius, + isOnline, + categoryOneOf, + statusOneOf, + languageOneOf, + searchTarget, + bbox, + zoom, + sortBy, + boostLanguagesQuery, + ], + ([newContentType]) => { + switch (newContentType) { + case ContentType.ALL: + page.value = 1; + break; + case ContentType.EVENTS: + eventPage.value = 1; + break; + case ContentType.GROUPS: + groupPage.value = 1; + break; + } + } +); + const { result: searchElementsResult, loading: searchLoading } = useQuery<{ searchEvents: Paginate>; searchGroups: Paginate>;