feat: ouverture du reader à la dernière page lue avec notification
This commit is contained in:
@@ -6,6 +6,7 @@ import { useEffect, useState } from "react";
|
|||||||
import { BookReader } from "@/components/reader/BookReader";
|
import { BookReader } from "@/components/reader/BookReader";
|
||||||
import { ImageOff } from "lucide-react";
|
import { ImageOff } from "lucide-react";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
|
import { useToast } from "@/components/ui/use-toast";
|
||||||
|
|
||||||
interface BookData {
|
interface BookData {
|
||||||
book: KomgaBook;
|
book: KomgaBook;
|
||||||
@@ -14,6 +15,7 @@ interface BookData {
|
|||||||
|
|
||||||
export default function BookPage({ params }: { params: { bookId: string } }) {
|
export default function BookPage({ params }: { params: { bookId: string } }) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { toast } = useToast();
|
||||||
const [data, setData] = useState<BookData | null>(null);
|
const [data, setData] = useState<BookData | null>(null);
|
||||||
const [isLoading, setIsLoading] = useState(true);
|
const [isLoading, setIsLoading] = useState(true);
|
||||||
const [error, setError] = useState<string | null>(null);
|
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");
|
throw new Error(data.error || "Erreur lors de la récupération du tome");
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
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);
|
setData(data);
|
||||||
setIsReading(true);
|
setIsReading(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -40,7 +51,7 @@ export default function BookPage({ params }: { params: { bookId: string } }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
fetchBookData();
|
fetchBookData();
|
||||||
}, [params.bookId]);
|
}, [params.bookId, toast]);
|
||||||
|
|
||||||
const handleCloseReader = () => {
|
const handleCloseReader = () => {
|
||||||
setIsReading(false);
|
setIsReading(false);
|
||||||
|
|||||||
@@ -27,12 +27,19 @@ interface BookReaderProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function BookReader({ book, pages, onClose }: 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 [isLoading, setIsLoading] = useState(true);
|
||||||
const [imageError, setImageError] = useState(false);
|
const [imageError, setImageError] = useState(false);
|
||||||
const [isDoublePage, setIsDoublePage] = useState(false);
|
const [isDoublePage, setIsDoublePage] = useState(false);
|
||||||
const pageCache = useRef<PageCache>({});
|
const pageCache = useRef<PageCache>({});
|
||||||
|
|
||||||
|
// Effet pour synchroniser la progression initiale
|
||||||
|
useEffect(() => {
|
||||||
|
if (book.readProgress?.page) {
|
||||||
|
syncReadProgress(book.readProgress.page);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
// Fonction pour synchroniser la progression
|
// Fonction pour synchroniser la progression
|
||||||
const syncReadProgress = useCallback(
|
const syncReadProgress = useCallback(
|
||||||
async (page: number) => {
|
async (page: number) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user