feat: clean cache on home
This commit is contained in:
@@ -1,12 +1,26 @@
|
|||||||
import { HomeContent } from "@/components/home/HomeContent";
|
import { HomeContent } from "@/components/home/HomeContent";
|
||||||
import { HomeService } from "@/lib/services/home.service";
|
import { HomeService } from "@/lib/services/home.service";
|
||||||
import { redirect } from "next/navigation";
|
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() {
|
export default async function HomePage() {
|
||||||
try {
|
try {
|
||||||
const data = await HomeService.getHomeData();
|
const data = await HomeService.getHomeData();
|
||||||
|
|
||||||
return <HomeContent data={data} />;
|
return <HomeContent data={data} refreshHome={refreshHome} />;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Si l'erreur indique une configuration manquante, rediriger vers les préférences
|
// Si l'erreur indique une configuration manquante, rediriger vers les préférences
|
||||||
if (error instanceof Error && error.message.includes("Configuration Komga manquante")) {
|
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 { SeriesService } from "@/lib/services/series.service";
|
||||||
import { PreferencesService } from "@/lib/services/preferences.service";
|
import { PreferencesService } from "@/lib/services/preferences.service";
|
||||||
import { revalidatePath } from "next/cache";
|
import { revalidatePath } from "next/cache";
|
||||||
import { RefreshButton } from "@/components/library/RefreshButton";
|
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
params: { seriesId: string };
|
params: { seriesId: string };
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { HeroSection } from "./HeroSection";
|
import { HeroSection } from "./HeroSection";
|
||||||
import { MediaRow } from "./MediaRow";
|
import { MediaRow } from "./MediaRow";
|
||||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||||
|
import { RefreshButton } from "@/components/library/RefreshButton";
|
||||||
|
|
||||||
interface HomeData {
|
interface HomeData {
|
||||||
ongoing: KomgaSeries[];
|
ongoing: KomgaSeries[];
|
||||||
@@ -10,9 +11,10 @@ interface HomeData {
|
|||||||
|
|
||||||
interface HomeContentProps {
|
interface HomeContentProps {
|
||||||
data: HomeData;
|
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
|
// Vérification des données pour le debug
|
||||||
// console.log("HomeContent - Données reçues:", {
|
// console.log("HomeContent - Données reçues:", {
|
||||||
// ongoingCount: data.ongoing?.length || 0,
|
// ongoingCount: data.ongoing?.length || 0,
|
||||||
@@ -47,6 +49,10 @@ export function HomeContent({ data }: HomeContentProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="container mx-auto px-4 py-8 space-y-12">
|
<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 */}
|
{/* Hero Section - Afficher uniquement si nous avons des séries en cours */}
|
||||||
{data.ongoing && data.ongoing.length > 0 && (
|
{data.ongoing && data.ongoing.length > 0 && (
|
||||||
<HeroSection series={optimizeHeroSeriesData(data.ongoing)} />
|
<HeroSection series={optimizeHeroSeriesData(data.ongoing)} />
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { BaseApiService } from "./base-api.service";
|
import { BaseApiService } from "./base-api.service";
|
||||||
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
import { KomgaBook, KomgaSeries } from "@/types/komga";
|
||||||
import { LibraryResponse } from "@/types/library";
|
import { LibraryResponse } from "@/types/library";
|
||||||
|
import { serverCacheService } from "./server-cache.service";
|
||||||
|
|
||||||
interface HomeData {
|
interface HomeData {
|
||||||
ongoing: KomgaSeries[];
|
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");
|
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