diff --git a/src/components/Library.tsx b/src/components/Library.tsx index bab702b..2a651ea 100644 --- a/src/components/Library.tsx +++ b/src/components/Library.tsx @@ -7,14 +7,31 @@ import { Icon } from "./Icon"; export function Library({ onOpen }: { onOpen: (book: Book) => void }) { const [books, setBooks] = useState([]); + const [loaded, setLoaded] = useState(false); const [busy, setBusy] = useState(false); const [notice, setNotice] = useState(null); - const refresh = () => listBooks().then(setBooks).catch(() => setBooks([])); + const refresh = () => + listBooks() + .then(setBooks) + .catch(() => setBooks([])) + .finally(() => setLoaded(true)); useEffect(() => { refresh(); }, []); + const handleExample = async () => { + const copy = exampleBook(); + if (isDesktop) { + try { + await saveBook(copy); + } catch (e) { + setNotice(`Could not save copy: ${e}`); + } + } + onOpen(copy); + }; + const removeBook = async (e: MouseEvent, id: string) => { e.stopPropagation(); await deleteBook(id); @@ -51,10 +68,12 @@ export function Library({ onOpen }: { onOpen: (book: Book) => void }) { {busy ? "Importing…" : "Import EPUB"} - + {loaded && books.length === 0 && ( + + )} {books.map((b) => (
loadBook(b.id).then(onOpen)}> {b.title || "Untitled"}