refactor: simplify HomePage and LibraryPage components by integrating ClientHomePage and ClientLibraryPage, enhancing data fetching and error handling
This commit is contained in:
@@ -1,50 +1,5 @@
|
||||
import { HomeContent } from "@/components/home/HomeContent";
|
||||
import { HomeService } from "@/lib/services/home.service";
|
||||
import { redirect } from "next/navigation";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { withPageTiming } from "@/lib/hoc/withPageTiming";
|
||||
import { ErrorMessage } from "@/components/ui/ErrorMessage";
|
||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||
import type { HomeData } from "@/lib/services/home.service";
|
||||
import { AppError } from "@/utils/errors";
|
||||
import { ClientHomePage } from "@/components/home/ClientHomePage";
|
||||
|
||||
async function refreshHome() {
|
||||
"use server";
|
||||
|
||||
try {
|
||||
await HomeService.invalidateHomeCache();
|
||||
revalidatePath("/");
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du rafraîchissement:", error);
|
||||
return { success: false, error: "Erreur lors du rafraîchissement de la page d'accueil" };
|
||||
}
|
||||
export default function HomePage() {
|
||||
return <ClientHomePage />;
|
||||
}
|
||||
|
||||
async function HomePage() {
|
||||
try {
|
||||
const data: HomeData = await HomeService.getHomeData();
|
||||
return <HomeContent data={data} refreshHome={refreshHome} />;
|
||||
} catch (error) {
|
||||
// Si l'erreur indique une configuration manquante, rediriger vers les préférences
|
||||
|
||||
if (error instanceof AppError) {
|
||||
if (error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) {
|
||||
redirect("/settings");
|
||||
}
|
||||
return (
|
||||
<main className="container mx-auto px-4 py-8">
|
||||
<ErrorMessage errorCode={error.code} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<main className="container mx-auto px-4 py-8">
|
||||
<ErrorMessage errorCode={ERROR_CODES.KOMGA.SERVER_UNREACHABLE} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default withPageTiming("HomePage", HomePage);
|
||||
|
||||
Reference in New Issue
Block a user