feat: enhance home and library pages by integrating new data fetching methods, improving error handling, and refactoring components for better structure
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 4m17s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 4m17s
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { ClientLibraryPage } from "./ClientLibraryPage";
|
||||
import { LibraryService } from "@/lib/services/library.service";
|
||||
import { LibraryClientWrapper } from "./LibraryClientWrapper";
|
||||
import { LibraryContent } from "./LibraryContent";
|
||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import type { UserPreferences } from "@/types/preferences";
|
||||
|
||||
interface PageProps {
|
||||
@@ -7,6 +12,8 @@ interface PageProps {
|
||||
searchParams: Promise<{ page?: string; unread?: string; search?: string; size?: string }>;
|
||||
}
|
||||
|
||||
const DEFAULT_PAGE_SIZE = 20;
|
||||
|
||||
export default async function LibraryPage({ params, searchParams }: PageProps) {
|
||||
const libraryId = (await params).libraryId;
|
||||
const unread = (await searchParams).unread;
|
||||
@@ -19,15 +26,49 @@ export default async function LibraryPage({ params, searchParams }: PageProps) {
|
||||
|
||||
// Utiliser le paramètre d'URL s'il existe, sinon utiliser la préférence utilisateur
|
||||
const unreadOnly = unread !== undefined ? unread === "true" : preferences.showOnlyUnread;
|
||||
const effectivePageSize = size
|
||||
? parseInt(size)
|
||||
: preferences.displayMode?.itemsPerPage || DEFAULT_PAGE_SIZE;
|
||||
|
||||
return (
|
||||
<ClientLibraryPage
|
||||
currentPage={currentPage}
|
||||
libraryId={libraryId}
|
||||
preferences={preferences}
|
||||
unreadOnly={unreadOnly}
|
||||
search={search}
|
||||
pageSize={size ? parseInt(size) : undefined}
|
||||
/>
|
||||
);
|
||||
try {
|
||||
const [series, library] = await Promise.all([
|
||||
LibraryService.getLibrarySeries(
|
||||
libraryId,
|
||||
currentPage - 1,
|
||||
effectivePageSize,
|
||||
unreadOnly,
|
||||
search
|
||||
),
|
||||
LibraryService.getLibrary(libraryId),
|
||||
]);
|
||||
|
||||
return (
|
||||
<LibraryClientWrapper
|
||||
libraryId={libraryId}
|
||||
currentPage={currentPage}
|
||||
unreadOnly={unreadOnly}
|
||||
search={search}
|
||||
pageSize={effectivePageSize}
|
||||
preferences={preferences}
|
||||
>
|
||||
<LibraryContent
|
||||
library={library}
|
||||
series={series}
|
||||
currentPage={currentPage}
|
||||
preferences={preferences}
|
||||
unreadOnly={unreadOnly}
|
||||
search={search}
|
||||
pageSize={effectivePageSize}
|
||||
/>
|
||||
</LibraryClientWrapper>
|
||||
);
|
||||
} catch (error) {
|
||||
const errorCode = error instanceof AppError ? error.code : ERROR_CODES.SERIES.FETCH_ERROR;
|
||||
|
||||
return (
|
||||
<main className="container mx-auto px-4 py-8">
|
||||
<ErrorMessage errorCode={errorCode} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user