feat: refresh in libraries and books lists
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { PaginatedSeriesGrid } from "@/components/library/PaginatedSeriesGrid";
|
||||
import { LibraryService } from "@/lib/services/library.service";
|
||||
import { PreferencesService } from "@/lib/services/preferences.service";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { RefreshButton } from "@/components/library/RefreshButton";
|
||||
|
||||
interface PageProps {
|
||||
params: { libraryId: string };
|
||||
@@ -9,6 +11,20 @@ interface PageProps {
|
||||
|
||||
const PAGE_SIZE = 20;
|
||||
|
||||
async function refreshLibrary(libraryId: string) {
|
||||
"use server";
|
||||
|
||||
try {
|
||||
await LibraryService.clearLibrarySeriesCache(libraryId);
|
||||
|
||||
revalidatePath(`/libraries/${libraryId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du rafraîchissement:", error);
|
||||
return { success: false, error: "Erreur lors du rafraîchissement de la bibliothèque" };
|
||||
}
|
||||
}
|
||||
|
||||
async function getLibrarySeries(libraryId: string, page: number = 1, unreadOnly: boolean = false) {
|
||||
try {
|
||||
const pageIndex = page - 1;
|
||||
@@ -46,11 +62,14 @@ export default async function LibraryPage({ params, searchParams }: PageProps) {
|
||||
<div className="container py-8 space-y-8">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-3xl font-bold">{library.name}</h1>
|
||||
{series.totalElements > 0 && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{series.totalElements} série{series.totalElements > 1 ? "s" : ""}
|
||||
</p>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
{series.totalElements > 0 && (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{series.totalElements} série{series.totalElements > 1 ? "s" : ""}
|
||||
</p>
|
||||
)}
|
||||
<RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} />
|
||||
</div>
|
||||
</div>
|
||||
<PaginatedSeriesGrid
|
||||
series={series.content || []}
|
||||
@@ -66,7 +85,10 @@ export default async function LibraryPage({ params, searchParams }: PageProps) {
|
||||
} catch (error) {
|
||||
return (
|
||||
<div className="container py-8 space-y-8">
|
||||
<h1 className="text-3xl font-bold">Séries</h1>
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-3xl font-bold">Séries</h1>
|
||||
<RefreshButton libraryId={params.libraryId} refreshLibrary={refreshLibrary} />
|
||||
</div>
|
||||
<div className="rounded-md bg-destructive/15 p-4">
|
||||
<p className="text-sm text-destructive">
|
||||
{error instanceof Error ? error.message : "Erreur lors de la récupération des séries"}
|
||||
|
||||
@@ -2,6 +2,8 @@ import { PaginatedBookGrid } from "@/components/series/PaginatedBookGrid";
|
||||
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 };
|
||||
@@ -23,6 +25,20 @@ async function getSeriesBooks(seriesId: string, page: number = 1, unreadOnly: bo
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshSeries(seriesId: string) {
|
||||
"use server";
|
||||
|
||||
try {
|
||||
await SeriesService.clearSeriesBooksCache(seriesId);
|
||||
await SeriesService.clearSeriesCache(seriesId);
|
||||
revalidatePath(`/series/${seriesId}`);
|
||||
return { success: true };
|
||||
} catch (error) {
|
||||
console.error("Erreur lors du rafraîchissement:", error);
|
||||
return { success: false, error: "Erreur lors du rafraîchissement de la série" };
|
||||
}
|
||||
}
|
||||
|
||||
export default async function SeriesPage({ params, searchParams }: PageProps) {
|
||||
const currentPage = searchParams.page ? parseInt(searchParams.page) : 1;
|
||||
const preferences = await PreferencesService.getPreferences();
|
||||
@@ -36,7 +52,7 @@ export default async function SeriesPage({ params, searchParams }: PageProps) {
|
||||
|
||||
return (
|
||||
<div className="container py-8 space-y-8">
|
||||
<SeriesHeader series={series} />
|
||||
<SeriesHeader series={series} refreshSeries={refreshSeries} />
|
||||
<PaginatedBookGrid
|
||||
books={books.content || []}
|
||||
currentPage={currentPage}
|
||||
|
||||
Reference in New Issue
Block a user