From 407d60c07460a5f683c1009f1b03500697d6d017 Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 12 Feb 2024 12:12:07 -0700 Subject: [PATCH] Using searching files is at /search. --- app/src/components/Search.js | 4 +++- app/src/hooks/customHooks.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/components/Search.js b/app/src/components/Search.js index 784dfca1..20554bc1 100644 --- a/app/src/components/Search.js +++ b/app/src/components/Search.js @@ -164,7 +164,8 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames) { { title: newSuggestions.fileGroups.toString(), type: 'files', - location: getLocationStr({q: searchStr}) + // Add search query onto current location. + location: getLocationStr({q: encodeURIComponent(searchStr)}, '/search') } ] }; @@ -179,6 +180,7 @@ export function useSearchSuggestions(defaultSearchStr, defaultTagNames) { if (newSuggestions && zimSum > 0) { results.zimsSum = { name: 'Zims', results: [ + // Navigating to Zims is not relative. We don't want to keep filters or other extra params. {title: zimSum.toString(), type: 'zims', location: `/search/zim?q=${encodeURIComponent(searchStr)}`} ], }; diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js index 7e6634c1..418bbbd4 100644 --- a/app/src/hooks/customHooks.js +++ b/app/src/hooks/customHooks.js @@ -132,10 +132,10 @@ export const useQuery = () => { setQuery(newQuery); } - const getLocationStr = (newSearchParams) => { + const getLocationStr = (newSearchParams, pathname) => { // Get the current location, but with new params appended. const newQuery = createSearchParams(getQuery(newSearchParams)); - return `${location.pathname}?${newQuery.toString()}` + return `${pathname || location.pathname}?${newQuery.toString()}` } return {searchParams, setSearchParams, setQuery, updateQuery, getLocationStr}