From 2a85abcb6dc45b9bbc9fd8549027273a9004756b Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Wed, 12 Feb 2025 16:09:56 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20ouverture=20du=20reader=20=C3=A0=20la?= =?UTF-8?q?=20derni=C3=A8re=20page=20lue=20avec=20notification?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/books/[bookId]/page.tsx | 13 ++++++++++++- src/components/reader/BookReader.tsx | 9 ++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/app/books/[bookId]/page.tsx b/src/app/books/[bookId]/page.tsx index 31ea0a6..cbce58a 100644 --- a/src/app/books/[bookId]/page.tsx +++ b/src/app/books/[bookId]/page.tsx @@ -6,6 +6,7 @@ import { useEffect, useState } from "react"; import { BookReader } from "@/components/reader/BookReader"; import { ImageOff } from "lucide-react"; import Image from "next/image"; +import { useToast } from "@/components/ui/use-toast"; interface BookData { book: KomgaBook; @@ -14,6 +15,7 @@ interface BookData { export default function BookPage({ params }: { params: { bookId: string } }) { const router = useRouter(); + const { toast } = useToast(); const [data, setData] = useState(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); @@ -29,6 +31,15 @@ export default function BookPage({ params }: { params: { bookId: string } }) { throw new Error(data.error || "Erreur lors de la récupération du tome"); } const data = await response.json(); + + // Si le livre a une progression de lecture, on l'affiche dans un toast + if (data.book.readProgress?.page > 0) { + toast({ + title: "Reprise de la lecture", + description: `Reprise à la page ${data.book.readProgress.page}`, + }); + } + setData(data); setIsReading(true); } catch (error) { @@ -40,7 +51,7 @@ export default function BookPage({ params }: { params: { bookId: string } }) { }; fetchBookData(); - }, [params.bookId]); + }, [params.bookId, toast]); const handleCloseReader = () => { setIsReading(false); diff --git a/src/components/reader/BookReader.tsx b/src/components/reader/BookReader.tsx index a24542d..4b22a2f 100644 --- a/src/components/reader/BookReader.tsx +++ b/src/components/reader/BookReader.tsx @@ -27,12 +27,19 @@ interface BookReaderProps { } export function BookReader({ book, pages, onClose }: BookReaderProps) { - const [currentPage, setCurrentPage] = useState(1); + const [currentPage, setCurrentPage] = useState(book.readProgress?.page || 1); const [isLoading, setIsLoading] = useState(true); const [imageError, setImageError] = useState(false); const [isDoublePage, setIsDoublePage] = useState(false); const pageCache = useRef({}); + // Effet pour synchroniser la progression initiale + useEffect(() => { + if (book.readProgress?.page) { + syncReadProgress(book.readProgress.page); + } + }, []); + // Fonction pour synchroniser la progression const syncReadProgress = useCallback( async (page: number) => {