refactor: simplify preferences handling and enhance pagination functionality in series grid

This commit is contained in:
Julien Froidefond
2025-04-01 07:01:40 +02:00
parent a2c7519ac5
commit 31b5930705
11 changed files with 201 additions and 135 deletions

View File

@@ -92,13 +92,7 @@ export default async function RootLayout({ children }: { children: React.ReactNo
}
if (preferencesData.status === "fulfilled") {
const { showThumbnails, cacheMode, showOnlyUnread, debug } = preferencesData.value;
preferences = {
showThumbnails,
cacheMode,
showOnlyUnread,
debug,
};
preferences = preferencesData.value;
}
} catch (error) {
console.error("Erreur lors du chargement des données de la sidebar:", error);

View File

@@ -13,19 +13,24 @@ import { AppError } from "@/utils/errors";
interface PageProps {
params: { seriesId: string };
searchParams: { page?: string; unread?: string };
searchParams: { page?: string; unread?: string; size?: string };
}
const PAGE_SIZE = 24;
const DEFAULT_PAGE_SIZE = 20;
async function getSeriesBooks(seriesId: string, page: number = 1, unreadOnly: boolean = false) {
async function getSeriesBooks(
seriesId: string,
page: number = 1,
unreadOnly: boolean = false,
size: number = DEFAULT_PAGE_SIZE
) {
try {
const pageIndex = page - 1;
const books: LibraryResponse<KomgaBook> = await SeriesService.getSeriesBooks(
seriesId,
pageIndex,
PAGE_SIZE,
size,
unreadOnly
);
const series: KomgaSeries = await SeriesService.getSeries(seriesId);
@@ -54,8 +59,10 @@ async function SeriesPage({ params, searchParams }: PageProps) {
const seriesId = (await params).seriesId;
const page = (await searchParams).page;
const unread = (await searchParams).unread;
const size = (await searchParams).size;
const currentPage = page ? parseInt(page) : 1;
const pageSize = size ? parseInt(size) : DEFAULT_PAGE_SIZE;
const preferences: UserPreferences = await PreferencesService.getPreferences();
// Utiliser le paramètre d'URL s'il existe, sinon utiliser la préférence utilisateur
@@ -63,7 +70,7 @@ async function SeriesPage({ params, searchParams }: PageProps) {
try {
const { data: books, series }: { data: LibraryResponse<KomgaBook>; series: KomgaSeries } =
await getSeriesBooks(seriesId, currentPage, unreadOnly);
await getSeriesBooks(seriesId, currentPage, unreadOnly, pageSize);
return (
<div className="container">
@@ -73,7 +80,6 @@ async function SeriesPage({ params, searchParams }: PageProps) {
currentPage={currentPage}
totalPages={books.totalPages}
totalElements={books.totalElements}
pageSize={PAGE_SIZE}
defaultShowOnlyUnread={preferences.showOnlyUnread}
showOnlyUnread={unreadOnly}
/>