refactor: enhance URL parameter handling in PaginatedSeriesGrid and PaginatedBookGrid components by adding replace option for router navigation
This commit is contained in:
@@ -39,7 +39,10 @@ export function PaginatedSeriesGrid({
|
|||||||
const { isCompact, itemsPerPage } = useDisplayPreferences();
|
const { isCompact, itemsPerPage } = useDisplayPreferences();
|
||||||
const { t } = useTranslate();
|
const { t } = useTranslate();
|
||||||
|
|
||||||
const updateUrlParams = async (updates: Record<string, string | null>) => {
|
const updateUrlParams = async (
|
||||||
|
updates: Record<string, string | null>,
|
||||||
|
replace: boolean = false
|
||||||
|
) => {
|
||||||
setIsChangingPage(true);
|
setIsChangingPage(true);
|
||||||
const params = new URLSearchParams(searchParams.toString());
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
|
|
||||||
@@ -51,7 +54,11 @@ export function PaginatedSeriesGrid({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await router.push(`${pathname}?${params.toString()}`);
|
if (replace) {
|
||||||
|
await router.replace(`${pathname}?${params.toString()}`);
|
||||||
|
} else {
|
||||||
|
await router.push(`${pathname}?${params.toString()}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset loading state when series change
|
// Reset loading state when series change
|
||||||
@@ -67,7 +74,7 @@ export function PaginatedSeriesGrid({
|
|||||||
// Apply default filter on initial load
|
// Apply default filter on initial load
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (defaultShowOnlyUnread && !searchParams.has("unread")) {
|
if (defaultShowOnlyUnread && !searchParams.has("unread")) {
|
||||||
updateUrlParams({ page: "1", unread: "true" });
|
updateUrlParams({ page: "1", unread: "true" }, true);
|
||||||
}
|
}
|
||||||
}, [defaultShowOnlyUnread, pathname, router, searchParams]);
|
}, [defaultShowOnlyUnread, pathname, router, searchParams]);
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ export function PaginatedBookGrid({
|
|||||||
const { isCompact, itemsPerPage } = useDisplayPreferences();
|
const { isCompact, itemsPerPage } = useDisplayPreferences();
|
||||||
const { t } = useTranslate();
|
const { t } = useTranslate();
|
||||||
|
|
||||||
const updateUrlParams = async (updates: Record<string, string | null>) => {
|
const updateUrlParams = async (
|
||||||
|
updates: Record<string, string | null>,
|
||||||
|
replace: boolean = false
|
||||||
|
) => {
|
||||||
setIsChangingPage(true);
|
setIsChangingPage(true);
|
||||||
const params = new URLSearchParams(searchParams.toString());
|
const params = new URLSearchParams(searchParams.toString());
|
||||||
|
|
||||||
@@ -50,7 +53,11 @@ export function PaginatedBookGrid({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await router.push(`${pathname}?${params.toString()}`);
|
if (replace) {
|
||||||
|
await router.replace(`${pathname}?${params.toString()}`);
|
||||||
|
} else {
|
||||||
|
await router.push(`${pathname}?${params.toString()}`);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Reset loading state when books change
|
// Reset loading state when books change
|
||||||
@@ -66,7 +73,7 @@ export function PaginatedBookGrid({
|
|||||||
// Apply default filter on initial load
|
// Apply default filter on initial load
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (defaultShowOnlyUnread && !searchParams.has("unread")) {
|
if (defaultShowOnlyUnread && !searchParams.has("unread")) {
|
||||||
updateUrlParams({ page: "1", unread: "true" });
|
updateUrlParams({ page: "1", unread: "true" }, true);
|
||||||
}
|
}
|
||||||
}, [defaultShowOnlyUnread, pathname, router, searchParams]);
|
}, [defaultShowOnlyUnread, pathname, router, searchParams]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user