diff --git a/src/components/Dock.tsx b/src/components/Dock.tsx index aa9f6f9..807eedf 100644 --- a/src/components/Dock.tsx +++ b/src/components/Dock.tsx @@ -25,6 +25,7 @@ function PdfDock() { const timer = useRef>(undefined); useEffect(() => { + if (!book) return; clearTimeout(timer.current); setBusy(true); timer.current = setTimeout(() => { @@ -44,7 +45,7 @@ function PdfDock() {
Preview - {busy ? "updating…" : TRIM_LABEL[book.settings.trim]} + {busy ? "updating…" : TRIM_LABEL[book?.settings.trim ?? "6x9"]}
{error ? (
{error}
@@ -58,19 +59,21 @@ function PdfDock() { } function HtmlDock() { - const chapters = useBook((s) => s.book.chapters); - const trim = useBook((s) => s.book.settings.trim); + const book = useBook((s) => s.book); const activeChapterId = useBook((s) => s.activeChapterId); + const chapters = book?.chapters ?? []; const idx = chapters.findIndex((c) => c.id === activeChapterId); - const chapter = chapters[idx]; - const html = useMemo(() => generateHTML(chapter.content, editorExtensions), [chapter.content]); + const chapter = chapters[idx] ?? chapters[0]; + const html = useMemo(() => (chapter ? generateHTML(chapter.content, editorExtensions) : ""), [chapter]); + + if (!book || !chapter) return null; return (
Preview - {TRIM_LABEL[trim]} · {idx + 1} of {chapters.length} + {TRIM_LABEL[book.settings.trim]} · {idx + 1} of {chapters.length}
diff --git a/src/components/Settings.tsx b/src/components/Settings.tsx index e0a7057..b0e2a99 100644 --- a/src/components/Settings.tsx +++ b/src/components/Settings.tsx @@ -28,12 +28,14 @@ function Field({ label, children }: { label: string; children: ReactNode }) { ); } -export function Settings({ onClose }: { onClose: () => void }) { - const metadata = useBook((s) => s.book.metadata); - const settings = useBook((s) => s.book.settings); +export function Settings({ onClose, onSave }: { onClose: () => void; onSave: () => void }) { + const book = useBook((s) => s.book); const setMetadata = useBook((s) => s.setMetadata); const setSettings = useBook((s) => s.setSettings); + if (!book) return null; + const { metadata, settings } = book; + return (
e.stopPropagation()}> @@ -81,6 +83,17 @@ export function Settings({ onClose }: { onClose: () => void }) { Add bleed for full-page images (print)
+
+ +
); diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index de66c2e..4a9837c 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -2,17 +2,18 @@ import { useBook } from "../store/useBook"; import { Icon } from "./Icon"; export function Sidebar() { - const chapters = useBook((s) => s.book.chapters); + const chapters = useBook((s) => s.book?.chapters ?? []); const activeChapterId = useBook((s) => s.activeChapterId); const setActiveChapter = useBook((s) => s.setActiveChapter); const addChapter = useBook((s) => s.addChapter); + const closeBook = useBook((s) => s.closeBook); return (