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:
@@ -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;
|
||||
|
||||
@@ -28,6 +28,7 @@ export class Storage {
|
||||
|
||||
setItem(key: string, value: unknown): void {
|
||||
if (value === undefined) {
|
||||
this.storage.removeItem(key);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user