feat: refresh buttons invalidate cache and show spinner during refresh
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 1m56s
All checks were successful
Deploy with Docker Compose / deploy (push) Successful in 1m56s
- Add revalidateForRefresh(scope, id) server action for home/library/series - Library/Series wrappers: revalidate cache then router.refresh(), 400ms delay for animation - Home: revalidate home-data + path before refresh - RefreshButton uses refreshLibrary from RefreshContext when not passed as prop - Library/Series pages pass id to wrapper for context and pull-to-refresh - read-progress: pass 'max' to revalidateTag for Next 16 types Made-with: Cursor
This commit is contained in:
@@ -20,8 +20,8 @@ export async function updateReadProgress(
|
||||
await BookService.updateReadProgress(bookId, page, completed);
|
||||
|
||||
// Invalider le cache home et libraries (statut de lecture des séries)
|
||||
revalidateTag(HOME_CACHE_TAG);
|
||||
revalidateTag(LIBRARY_SERIES_CACHE_TAG);
|
||||
revalidateTag(HOME_CACHE_TAG, "max");
|
||||
revalidateTag(LIBRARY_SERIES_CACHE_TAG, "max");
|
||||
|
||||
return { success: true, message: "Progression mise à jour" };
|
||||
} catch (error) {
|
||||
@@ -42,8 +42,8 @@ export async function deleteReadProgress(
|
||||
await BookService.deleteReadProgress(bookId);
|
||||
|
||||
// Invalider le cache home et libraries (statut de lecture des séries)
|
||||
revalidateTag(HOME_CACHE_TAG);
|
||||
revalidateTag(LIBRARY_SERIES_CACHE_TAG);
|
||||
revalidateTag(HOME_CACHE_TAG, "max");
|
||||
revalidateTag(LIBRARY_SERIES_CACHE_TAG, "max");
|
||||
|
||||
return { success: true, message: "Progression supprimée" };
|
||||
} catch (error) {
|
||||
|
||||
32
src/app/actions/refresh.ts
Normal file
32
src/app/actions/refresh.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath, revalidateTag } from "next/cache";
|
||||
import { LIBRARY_SERIES_CACHE_TAG } from "@/lib/services/library.service";
|
||||
|
||||
const HOME_CACHE_TAG = "home-data";
|
||||
|
||||
export type RefreshScope = "home" | "library" | "series";
|
||||
|
||||
/**
|
||||
* Invalide le cache Next.js pour forcer un re-fetch au prochain router.refresh().
|
||||
* À appeler côté client avant router.refresh() sur les boutons / pull-to-refresh.
|
||||
*/
|
||||
export async function revalidateForRefresh(scope: RefreshScope, id: string): Promise<void> {
|
||||
switch (scope) {
|
||||
case "home":
|
||||
revalidateTag(HOME_CACHE_TAG, "max");
|
||||
revalidatePath("/");
|
||||
break;
|
||||
case "library":
|
||||
revalidateTag(LIBRARY_SERIES_CACHE_TAG, "max");
|
||||
revalidatePath(`/libraries/${id}`);
|
||||
revalidatePath("/libraries");
|
||||
break;
|
||||
case "series":
|
||||
revalidatePath(`/series/${id}`);
|
||||
revalidatePath("/series");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user