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

@@ -7,6 +7,7 @@ import { ClientOfflineBookService } from "@/lib/services/client-offlinebook.serv
import { useState } from "react";
import { useTranslation } from "react-i18next";
import logger from "@/lib/logger";
import { updateReadProgress } from "@/app/actions/read-progress";
interface MarkAsReadButtonProps {
bookId: string;
@@ -32,16 +33,11 @@ export function MarkAsReadButton({
setIsLoading(true);
try {
ClientOfflineBookService.removeCurrentPageById(bookId);
const response = await fetch(`/api/komga/books/${bookId}/read-progress`, {
method: "PATCH",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ page: pagesCount, completed: true }),
});
const result = await updateReadProgress(bookId, pagesCount, true);
if (!response.ok) {
throw new Error(t("books.actions.markAsRead.error.update"));
if (!result.success) {
throw new Error(result.message);
}
toast({