import { useEffect, useState, type MouseEvent } from "react"; import { type BookSummary, deleteBook, exampleBook, listBooks, loadBook, newBook } from "../library"; import type { Book } from "../model/book"; import { Icon } from "./Icon"; export function Library({ onOpen }: { onOpen: (book: Book) => void }) { const [books, setBooks] = useState([]); const refresh = () => listBooks().then(setBooks).catch(() => setBooks([])); useEffect(() => { refresh(); }, []); const removeBook = async (e: MouseEvent, id: string) => { e.stopPropagation(); await deleteBook(id); refresh(); }; return (
{books.map((b) => (
loadBook(b.id).then(onOpen)}> {b.title || "Untitled"} {b.author && {b.author}}
))}
); }