/** * App — root component with page navigation (library ↔ book detail ↔ reading view). */ import { useState, lazy, Suspense } from "react"; import "./App.css"; import "./reader.css"; const LibraryPage = lazy(() => import("./pages/LibraryPage")); const BookDetailPage = lazy(() => import("./pages/BookDetailPage")); const ReadingPage = lazy(() => import("./pages/ReadingPage")); type View = | { kind: "library" } | { kind: "detail"; bookId: number } | { kind: "reader"; book: import("./types").BookDetail }; function LoadingFallback() { return (

Loading...

); } export default function App() { const [view, setView] = useState({ kind: "library" }); const handleBookSelect = (id: number) => { setView({ kind: "detail", bookId: id }); }; const handleBack = () => { setView({ kind: "library" }); }; const handleStartReading = (book: import("./types").BookDetail) => { setView({ kind: "reader", book }); }; return (
}> {view.kind === "library" && ( )} {view.kind === "detail" && view.bookId !== undefined && ( )} {view.kind === "reader" && view.book !== undefined && ( )}
); }