import { useEffect, useState } from "react"; import { BookOpen, LibraryBig, RotateCcw } from "lucide-react"; import type { BookDto, ProgressDto } from "@readabook/shared"; import { api, getApiFallback } from "../api/client"; import { EmptyState, ErrorRibbon, FormatPill, LoadingState, Meter, Panel } from "../components/ui"; import { navigate } from "../router"; export function BookPage({ bookId }: { bookId: number }) { const [book, setBook] = useState(null); const [progress, setProgress] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(); async function loadBook() { setLoading(true); setError(undefined); try { const [nextBook, nextProgress] = await Promise.all([api.book(bookId), api.progress(bookId)]); setBook(nextBook); setProgress(nextProgress); } catch (loadError) { const fallback = getApiFallback(loadError); setBook(fallback ?? null); setProgress(null); setError(fallback ? "Fiche chargee en mode secours." : "Fiche livre indisponible."); } finally { setLoading(false); } } useEffect(() => { let alive = true; loadBook().finally(() => { if (!alive) return; }); return () => { alive = false; }; }, [bookId]); if (loading && !book) return ; if (!book) { return ( ); } return (
{book.coverPath ? : }
{book.language ?? "langue inconnue"}

{book.title}

{book.author ?? "Auteur inconnu"}

{book.description ?? "Notice absente du catalogue."}

{progress && }
{error && ( )}
); }