fix(persist): persist new books on create

A freshly created book lived only in memory until the first edit, so
quitting beforehand lost it and it never appeared in the library. Save
it to disk on creation via a shared createAndOpenBook used by both the
Library card and the New Book menu action.

Claude-Session: https://claude.ai/code/session_01RzTWrLiy4zGuw2hZSQGamk
This commit is contained in:
pj committed 2026-06-22 13:17:50 -04:00
1 parent 258d5e5209
commit 6e2ca9c4bc
3 files changed
+19 -4

No files matched your search

+2 -2
View File
@@ -1,5 +1,5 @@
import { useEffect, useState } from "react";
import { type BookSummary, deleteBook, exampleBook, listBooks, loadBook, newBook, saveBook } from "../library";
import { type BookSummary, createAndOpenBook, deleteBook, exampleBook, listBooks, loadBook, saveBook } from "../library";
import type { Book } from "../model/book";
import { importEpub } from "../import/epub";
import { isDesktop } from "../ipc";
@@ -64,7 +64,7 @@ export function Library({ onOpen }: { onOpen: (book: Book) => void }) {
<div className="library">
<header className="library-head" data-tauri-drag-region />
<div className="shelf">
<button className="card card-action" onClick={() => onOpen(newBook())}>
<button className="card card-action" onClick={() => createAndOpenBook(onOpen, setNotice)}>
<Icon d="M12 5v14M5 12h14" size={20} />
<span>New book</span>
</button>