--- export const prerender = false; import PageLayout from "@/layouts/Base.astro"; import BookCard from "@/components/page/BookCard.astro"; type Book = { id: number; title: string; authors: string; cover_url: string | null; notes: string | null; status: "read" | "reading" | "want"; }; const meta = { title: "/library", description: "Books I'm reading, have read, and want to read", }; let books: Book[] = []; let error: string | null = null; try { const res = await fetch( "https://library.stevedylan.dev/api/books?status=all", ); if (res.ok) { books = await res.json(); } else { error = `API returned ${res.status}`; } } catch (e) { error = e instanceof Error ? e.message : "Failed to reach library API"; } const reading = books.filter((b) => b.status === "reading"); const read = books.filter((b) => b.status === "read"); const want = books.filter((b) => b.status === "want"); const sections: { label: string; items: Book[] }[] = [ { label: "Reading", items: reading }, { label: "Read", items: read }, { label: "Want to Read", items: want }, ]; ---

/library

{error ? (

Could not load books: {error}

) : books.length === 0 ? (

no books yet

) : (
{sections.filter((s) => s.items.length > 0).map((section) => (

{section.label}

{section.items.map((book) => ( ))}
))}
)}