From 7201a34607700a75954ae2b548b22e55b4913d25 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Fri, 27 Dec 2024 04:11:02 +0100 Subject: [PATCH] Preserve saved search filters on navigate back The saved search got restored and then "navigate" was called to set the "query" in the url, this however caused the "location key" to change which then made it impossible to load the applied filters from the session storage when going back in the history --- src/modules/source/screens/SourceMangas.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/modules/source/screens/SourceMangas.tsx b/src/modules/source/screens/SourceMangas.tsx index 08b4ae03..8da6972c 100644 --- a/src/modules/source/screens/SourceMangas.tsx +++ b/src/modules/source/screens/SourceMangas.tsx @@ -7,7 +7,7 @@ */ import { useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'; -import { useParams, useNavigate, useLocation } from 'react-router-dom'; +import { useParams, useNavigate, useLocation, useSearchParams } from 'react-router-dom'; import IconButton from '@mui/material/IconButton'; import SettingsIcon from '@mui/icons-material/Settings'; import { useQueryParam, StringParam } from 'use-query-params'; @@ -208,6 +208,7 @@ export function SourceMangas() { const { sourceId } = useParams<{ sourceId: string }>(); + const [searchParams, setSearchParams] = useSearchParams(); const navigate = useNavigate(); const location = useLocation(); const { key: locationKey, state: locationState } = location; @@ -220,7 +221,7 @@ export function SourceMangas() { const { settings: { hideLibraryEntries }, } = useMetadataServerSettings(); - + console.log('@asdf', locationKey); const [sourceGridLayout] = useLocalStorage('source-grid-layout', GridLayout.Compact); const [query] = useQueryParam('query', StringParam); const [currentFiltersToApply, setCurrentFiltersToApply] = useSessionStorage( @@ -304,13 +305,10 @@ export function SourceMangas() { setFiltersToApply(savedSearchFilters); } - navigate( - { - pathname: '', - search: savedSearchQuery ? `query=${savedSearchQuery}` : undefined, - }, - { state: { ...locationState, contentType: SourceContentType.SEARCH } }, - ); + if (savedSearchQuery) { + searchParams.set('query', savedSearchQuery); + setSearchParams(searchParams); + } }, [savedSearches, locationState], );