From 1df4b4b311e5d4042a419db3788193c93fcf0c3d Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 14 Apr 2024 15:18:51 +0200 Subject: [PATCH] Fix/source mangas applied filters lost when triggering search (#741) * Delete storage item when setting "undefined" * Preserve source browse filters on search The set filters were lost in case a search was triggered --- src/screens/SourceMangas.tsx | 20 ++++++++++++++++++-- src/util/AppStorage.ts | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/screens/SourceMangas.tsx b/src/screens/SourceMangas.tsx index 432f43bb..f7170d0a 100644 --- a/src/screens/SourceMangas.tsx +++ b/src/screens/SourceMangas.tsx @@ -236,10 +236,14 @@ export function SourceMangas() { const { options } = useLibraryOptionsContext(); const [query] = useQueryParam('query', StringParam); - const [filtersToApply, setFiltersToApply] = useSessionStorage( - `source-mangas-location-${locationKey}-${sourceId}-filters`, + const [currentFiltersToApply, setCurrentFiltersToApply] = useSessionStorage( + `source-mangas-${sourceId}-filters`, [], ); + const [filtersToApply, setLocationFiltersToApply] = useSessionStorage( + `source-mangas-location-${locationKey}-${sourceId}-filters`, + currentFiltersToApply ?? [], + ); const [dialogFiltersToApply, setDialogFiltersToApply] = useState(filtersToApply); const [resetScrollPosition, setResetScrollPosition] = useState(false); const [contentType, setContentType] = useSessionStorage( @@ -247,6 +251,18 @@ export function SourceMangas() { query ? SourceContentType.SEARCH : initialContentType, ); + useEffect( + () => () => { + setCurrentFiltersToApply(undefined); + }, + [sourceId], + ); + + const setFiltersToApply = (filters: IPos[]) => { + setCurrentFiltersToApply(filters); + setLocationFiltersToApply(filters); + }; + const [loadPage, { data, isLoading: loading, size: lastPageNum, abortRequest, filteredOutAllItemsOfFetchedPage }] = useSourceManga(sourceId, contentType, query, filtersToApply, 1, hideLibraryEntries); const isLoading = loading || filteredOutAllItemsOfFetchedPage; diff --git a/src/util/AppStorage.ts b/src/util/AppStorage.ts index e5088201..0e458d01 100644 --- a/src/util/AppStorage.ts +++ b/src/util/AppStorage.ts @@ -28,6 +28,7 @@ export class Storage { setItem(key: string, value: unknown): void { if (value === undefined) { + this.storage.removeItem(key); return; }