refactor: use Server Actions for read progress updates

- Create src/app/actions/read-progress.ts with updateReadProgress and deleteReadProgress
- Update mark-as-read-button and mark-as-unread-button to use Server Actions
- Update usePageNavigation hook to use Server Action
- Use revalidateTag with 'min' profile for cache invalidation
This commit is contained in:
2026-02-28 10:34:26 +01:00
parent ecce0a9738
commit 03cb46f81b
4 changed files with 64 additions and 19 deletions

View File

@@ -3,6 +3,7 @@ import { useRouter } from "next/navigation";
import { ClientOfflineBookService } from "@/lib/services/client-offlinebook.service";
import type { KomgaBook } from "@/types/komga";
import logger from "@/lib/logger";
import { updateReadProgress } from "@/app/actions/read-progress";
interface UsePageNavigationProps {
book: KomgaBook;
@@ -48,11 +49,7 @@ export function usePageNavigation({
try {
ClientOfflineBookService.setCurrentPage(bookRef.current, page);
const completed = page === pagesLengthRef.current;
await fetch(`/api/komga/books/${bookRef.current.id}/read-progress`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ page, completed }),
});
await updateReadProgress(bookRef.current.id, page, completed);
} catch (error) {
logger.error({ err: error }, "Sync error:");
}