feat: ouverture du reader à la dernière page lue avec notification

This commit is contained in:
Julien Froidefond
2025-02-12 16:09:56 +01:00
parent edfaa1b01c
commit 2a85abcb6d
2 changed files with 20 additions and 2 deletions

View File

@@ -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<BookData | null>(null);
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<string | null>(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);

View File

@@ -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<PageCache>({});
// 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) => {