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
This commit is contained in:
schroda
2024-04-14 15:18:51 +02:00
committed by GitHub
parent d0d21b00d5
commit 1df4b4b311
2 changed files with 19 additions and 2 deletions

View File

@@ -236,10 +236,14 @@ export function SourceMangas() {
const { options } = useLibraryOptionsContext();
const [query] = useQueryParam('query', StringParam);
const [filtersToApply, setFiltersToApply] = useSessionStorage<IPos[]>(
`source-mangas-location-${locationKey}-${sourceId}-filters`,
const [currentFiltersToApply, setCurrentFiltersToApply] = useSessionStorage<IPos[] | undefined>(
`source-mangas-${sourceId}-filters`,
[],
);
const [filtersToApply, setLocationFiltersToApply] = useSessionStorage<IPos[]>(
`source-mangas-location-${locationKey}-${sourceId}-filters`,
currentFiltersToApply ?? [],
);
const [dialogFiltersToApply, setDialogFiltersToApply] = useState<IPos[]>(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;

View File

@@ -28,6 +28,7 @@ export class Storage {
setItem(key: string, value: unknown): void {
if (value === undefined) {
this.storage.removeItem(key);
return;
}