diff --git a/src/components/Library.tsx b/src/components/Library.tsx index dfb42c5..bab702b 100644 --- a/src/components/Library.tsx +++ b/src/components/Library.tsx @@ -1,10 +1,14 @@ import { useEffect, useState, type MouseEvent } from "react"; -import { type BookSummary, deleteBook, exampleBook, listBooks, loadBook, newBook } from "../library"; +import { type BookSummary, deleteBook, exampleBook, listBooks, loadBook, newBook, saveBook } from "../library"; import type { Book } from "../model/book"; +import { importEpub } from "../import/epub"; +import { isDesktop } from "../ipc"; import { Icon } from "./Icon"; export function Library({ onOpen }: { onOpen: (book: Book) => void }) { const [books, setBooks] = useState([]); + const [busy, setBusy] = useState(false); + const [notice, setNotice] = useState(null); const refresh = () => listBooks().then(setBooks).catch(() => setBooks([])); useEffect(() => { @@ -17,6 +21,24 @@ export function Library({ onOpen }: { onOpen: (book: Book) => void }) { refresh(); }; + const handleImport = async () => { + if (!isDesktop) { + setNotice('Import runs in the desktop app only — open the window from "pnpm tauri dev".'); + return; + } + setBusy(true); + try { + const book = await importEpub(); + if (!book) return; + await saveBook(book); + onOpen(book); + } catch (e) { + setNotice(`Import failed: ${e}`); + } finally { + setBusy(false); + } + }; + return (
@@ -25,6 +47,10 @@ export function Library({ onOpen }: { onOpen: (book: Book) => void }) { New book +
))} + {notice && ( +
setNotice(null)}> + {notice} +
+ )} ); }