feat(series): mark as unread
This commit is contained in:
@@ -22,3 +22,15 @@ export async function PATCH(request: Request, { params }: { params: { bookId: st
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
export async function DELETE(request: Request, { params }: { params: { bookId: string } }) {
|
||||||
|
try {
|
||||||
|
await BookService.updateReadProgress(params.bookId, 1, false);
|
||||||
|
return NextResponse.json({ message: "Progression supprimée avec succès" });
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API Delete Read Progress - Erreur:", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Erreur lors de la suppression de la progression" },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { KomgaBook } from "@/types/komga";
|
|||||||
import { formatDate } from "@/lib/utils";
|
import { formatDate } from "@/lib/utils";
|
||||||
import { Cover } from "@/components/ui/cover";
|
import { Cover } from "@/components/ui/cover";
|
||||||
import { MarkAsReadButton } from "@/components/ui/mark-as-read-button";
|
import { MarkAsReadButton } from "@/components/ui/mark-as-read-button";
|
||||||
|
import { MarkAsUnreadButton } from "@/components/ui/mark-as-unread-button";
|
||||||
import { BookOfflineButton } from "@/components/ui/book-offline-button";
|
import { BookOfflineButton } from "@/components/ui/book-offline-button";
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
@@ -78,6 +79,19 @@ export function BookGrid({ books, onBookClick }: BookGridProps) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleMarkAsUnread = (bookId: string) => {
|
||||||
|
setLocalBooks((prevBooks) =>
|
||||||
|
prevBooks.map((book) =>
|
||||||
|
book.id === bookId
|
||||||
|
? {
|
||||||
|
...book,
|
||||||
|
readProgress: null,
|
||||||
|
}
|
||||||
|
: book
|
||||||
|
)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6">
|
<div className="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6">
|
||||||
{localBooks.map((book) => {
|
{localBooks.map((book) => {
|
||||||
@@ -114,6 +128,14 @@ export function BookGrid({ books, onBookClick }: BookGridProps) {
|
|||||||
className="bg-white/90 hover:bg-white text-black shadow-sm"
|
className="bg-white/90 hover:bg-white text-black shadow-sm"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{isRead && (
|
||||||
|
<MarkAsUnreadButton
|
||||||
|
bookId={book.id}
|
||||||
|
isRead={isRead}
|
||||||
|
onSuccess={() => handleMarkAsUnread(book.id)}
|
||||||
|
className="bg-white/90 hover:bg-white text-black shadow-sm"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
<BookOfflineButton
|
<BookOfflineButton
|
||||||
book={book}
|
book={book}
|
||||||
className="bg-white/90 hover:bg-white text-black shadow-sm"
|
className="bg-white/90 hover:bg-white text-black shadow-sm"
|
||||||
|
|||||||
60
src/components/ui/mark-as-unread-button.tsx
Normal file
60
src/components/ui/mark-as-unread-button.tsx
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { XCircle } from "lucide-react";
|
||||||
|
import { Button } from "./button";
|
||||||
|
import { useToast } from "./use-toast";
|
||||||
|
|
||||||
|
interface MarkAsUnreadButtonProps {
|
||||||
|
bookId: string;
|
||||||
|
isRead: boolean;
|
||||||
|
onSuccess?: () => void;
|
||||||
|
className?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function MarkAsUnreadButton({
|
||||||
|
bookId,
|
||||||
|
isRead = false,
|
||||||
|
onSuccess,
|
||||||
|
className,
|
||||||
|
}: MarkAsUnreadButtonProps) {
|
||||||
|
const { toast } = useToast();
|
||||||
|
|
||||||
|
const handleMarkAsUnread = async (e: React.MouseEvent) => {
|
||||||
|
e.stopPropagation(); // Empêcher la propagation au parent
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/komga/books/${bookId}/read-progress`, {
|
||||||
|
method: "DELETE",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Erreur lors de la mise à jour");
|
||||||
|
}
|
||||||
|
|
||||||
|
toast({
|
||||||
|
title: "Succès",
|
||||||
|
description: "Le tome a été marqué comme non lu",
|
||||||
|
});
|
||||||
|
onSuccess?.();
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Erreur lors de la mise à jour du progresseur de lecture:", error);
|
||||||
|
toast({
|
||||||
|
title: "Erreur",
|
||||||
|
description: "Impossible de marquer le tome comme non lu",
|
||||||
|
variant: "destructive",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Button
|
||||||
|
variant="ghost"
|
||||||
|
size="icon"
|
||||||
|
onClick={handleMarkAsUnread}
|
||||||
|
className={`h-8 w-8 p-0 rounded-br-lg rounded-tl-lg ${className}`}
|
||||||
|
disabled={!isRead}
|
||||||
|
aria-label="Marquer comme non lu"
|
||||||
|
>
|
||||||
|
<XCircle className="h-5 w-5" />
|
||||||
|
</Button>
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user