Restore previous content type when clearing search (#742)

After clearing the current search the initial content type was always restored instead of the previous selected content type
This commit is contained in:
schroda
2024-04-14 15:22:35 +02:00
committed by GitHub
parent 1df4b4b311
commit 418da46c62

View File

@@ -246,14 +246,19 @@ export function SourceMangas() {
);
const [dialogFiltersToApply, setDialogFiltersToApply] = useState<IPos[]>(filtersToApply);
const [resetScrollPosition, setResetScrollPosition] = useState(false);
const [contentType, setContentType] = useSessionStorage(
const [currentContentType, setCurrentContentType] = useSessionStorage<SourceContentType | undefined>(
`source-mangas-${sourceId}-content-type`,
initialContentType,
);
const [contentType, setLocationContentType] = useSessionStorage(
`source-mangas-location-${locationKey}-${sourceId}-content-type`,
query ? SourceContentType.SEARCH : initialContentType,
query ? SourceContentType.SEARCH : currentContentType!,
);
useEffect(
() => () => {
setCurrentFiltersToApply(undefined);
setCurrentContentType(undefined);
},
[sourceId],
);
@@ -263,6 +268,11 @@ export function SourceMangas() {
setLocationFiltersToApply(filters);
};
const setContentType = (newContentType: SourceContentType) => {
setCurrentContentType(newContentType);
setLocationContentType(newContentType);
};
const [loadPage, { data, isLoading: loading, size: lastPageNum, abortRequest, filteredOutAllItemsOfFetchedPage }] =
useSourceManga(sourceId, contentType, query, filtersToApply, 1, hideLibraryEntries);
const isLoading = loading || filteredOutAllItemsOfFetchedPage;