diff --git a/apps/web/src/pages/BookErrorPages.test.ts b/apps/web/src/pages/BookErrorPages.test.ts new file mode 100644 index 0000000..5e0e65a --- /dev/null +++ b/apps/web/src/pages/BookErrorPages.test.ts @@ -0,0 +1,23 @@ +import { readFileSync } from "node:fs"; +import { describe, expect, it } from "vitest"; + +describe("book missing error pages", () => { + it("does not render fallback books on the book detail page", () => { + const source = readFileSync(new URL("./BookPage.tsx", import.meta.url), "utf8"); + + expect(source).not.toContain("getApiFallback"); + expect(source).toContain("setBook(null)"); + expect(source).toContain("Livre introuvable"); + expect(source).toContain("Ce livre n'existe pas dans le catalogue."); + }); + + it("does not open the reader with a fallback book", () => { + const source = readFileSync(new URL("./ReaderPage.tsx", import.meta.url), "utf8"); + + expect(source).not.toContain("getApiFallback"); + expect(source).toContain("setBook(null)"); + expect(source).toContain("reader-missing-page"); + expect(source).toContain("Livre introuvable"); + expect(source).toContain("Ce livre n'existe pas dans le catalogue."); + }); +}); diff --git a/apps/web/src/pages/BookPage.tsx b/apps/web/src/pages/BookPage.tsx index 2e607ce..5b41915 100644 --- a/apps/web/src/pages/BookPage.tsx +++ b/apps/web/src/pages/BookPage.tsx @@ -1,7 +1,7 @@ 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 { api } from "../api/client"; import { cleanBookDescription } from "../book/description"; import { bookDisplayTitle, bookMetadataState, bookMetadataStateLabel, bookSeriesInfo, displayPublishedDate } from "../book/metadata"; import { EmptyState, ErrorRibbon, FormatPill, LoadingState, Meter, Panel } from "../components/ui"; @@ -17,14 +17,17 @@ export function BookPage({ bookId }: { bookId: number }) { setLoading(true); setError(undefined); try { - const [nextBook, nextProgress] = await Promise.all([api.book(bookId), api.progress(bookId)]); + const nextBook = await api.book(bookId); setBook(nextBook); - setProgress(nextProgress); - } catch (loadError) { - const fallback = getApiFallback(loadError); - setBook(fallback ?? null); + try { + setProgress(await api.progress(bookId)); + } catch { + setProgress(null); + } + } catch { + setBook(null); setProgress(null); - setError(fallback ? "Fiche chargee en mode secours." : "Fiche livre indisponible."); + setError("Ce livre n'existe pas dans le catalogue."); } finally { setLoading(false); } @@ -43,13 +46,20 @@ export function BookPage({ bookId }: { bookId: number }) { if (loading && !book) return ; if (!book) { return ( - - - - +
+ + +
+ + +
+
+
); } diff --git a/apps/web/src/pages/HomePage.tsx b/apps/web/src/pages/HomePage.tsx index a6f72c6..ba60c05 100644 --- a/apps/web/src/pages/HomePage.tsx +++ b/apps/web/src/pages/HomePage.tsx @@ -8,14 +8,12 @@ import { navigate } from "../router"; export function HomePage() { const [state, setState] = useState(null); - const [fallback, setFallback] = useState(false); useEffect(() => { let alive = true; Promise.all([api.books(), api.continueReading(), api.libraries(), api.jobs()]) .then(([books, continueReading, libraries, jobs]) => { if (!alive) return; - setFallback(books.some((book) => book.filePath.startsWith("/library/")) && jobs.length === 1); setState({ books, continueReading, libraries, jobs }); }) .catch(() => { @@ -50,7 +48,7 @@ export function HomePage() {

Bibliotheque personnelle

Reprendre la lecture.

- {fallback ? "API absente ou incomplete : specimens de demonstration actifs." : "Catalogue branche sur le serveur local."} + Catalogue branche sur le serveur local.
+ + + + + ); + } + return ( )} > - {!book ? ( -
- {error ?? "Chargement du livre."} - -
- ) : book.format === "pdf" ? ( + {book.format === "pdf" ? (