feat: clean cache on home
This commit is contained in:
@@ -1,12 +1,26 @@
|
||||
import { HomeContent } from "@/components/home/HomeContent";
|
||||
import { HomeService } from "@/lib/services/home.service";
|
||||
import { redirect } from "next/navigation";
|
||||
import { revalidatePath } from "next/cache";
|
||||
|
||||
async function refreshHome() {
|
||||
"use server";
|
||||
|
||||
try {
|
||||
await HomeService.clearHomeCache();
|
||||
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 async function HomePage() {
|
||||
try {
|
||||
const data = await HomeService.getHomeData();
|
||||
|
||||
return <HomeContent data={data} />;
|
||||
return <HomeContent data={data} refreshHome={refreshHome} />;
|
||||
} catch (error) {
|
||||
// Si l'erreur indique une configuration manquante, rediriger vers les préférences
|
||||
if (error instanceof Error && error.message.includes("Configuration Komga manquante")) {
|
||||
|
||||
@@ -3,7 +3,6 @@ import { SeriesHeader } from "@/components/series/SeriesHeader";
|
||||
import { SeriesService } from "@/lib/services/series.service";
|
||||
import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RefreshButton } from "@/components/library/RefreshButton";
|
||||
|
||||
interface PageProps {
|
||||
params: { seriesId: string };
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { HeroSection } from "./HeroSection";
|
||||
import { MediaRow } from "./MediaRow";
|
||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||
import { RefreshButton } from "@/components/library/RefreshButton";
|
||||
|
||||
interface HomeData {
|
||||
ongoing: KomgaSeries[];
|
||||
@@ -10,9 +11,10 @@ interface HomeData {
|
||||
|
||||
interface HomeContentProps {
|
||||
data: HomeData;
|
||||
refreshHome: () => Promise<{ success: boolean; error?: string }>;
|
||||
}
|
||||
|
||||
export function HomeContent({ data }: HomeContentProps) {
|
||||
export function HomeContent({ data, refreshHome }: HomeContentProps) {
|
||||
// Vérification des données pour le debug
|
||||
// console.log("HomeContent - Données reçues:", {
|
||||
// ongoingCount: data.ongoing?.length || 0,
|
||||
@@ -47,6 +49,10 @@ export function HomeContent({ data }: HomeContentProps) {
|
||||
|
||||
return (
|
||||
<main className="container mx-auto px-4 py-8 space-y-12">
|
||||
<div className="flex justify-between items-center">
|
||||
<h1 className="text-3xl font-bold">Accueil</h1>
|
||||
<RefreshButton libraryId="home" refreshLibrary={refreshHome} />
|
||||
</div>
|
||||
{/* Hero Section - Afficher uniquement si nous avons des séries en cours */}
|
||||
{data.ongoing && data.ongoing.length > 0 && (
|
||||
<HeroSection series={optimizeHeroSeriesData(data.ongoing)} />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { BaseApiService } from "./base-api.service";
|
||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||
import { LibraryResponse } from "@/types/library";
|
||||
import { serverCacheService } from "./server-cache.service";
|
||||
|
||||
interface HomeData {
|
||||
ongoing: KomgaSeries[];
|
||||
@@ -63,4 +64,10 @@ export class HomeService extends BaseApiService {
|
||||
return this.handleError(error, "Impossible de récupérer les données de la page d'accueil");
|
||||
}
|
||||
}
|
||||
|
||||
static async clearHomeCache() {
|
||||
serverCacheService.delete("home-ongoing");
|
||||
serverCacheService.delete("home-recently-read");
|
||||
serverCacheService.delete("home-on-deck");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user