feat: create and edit manual books #6

Merged
chris-paganon merged 10 commits from feat/manual-books into master 2026-11-14 18:29:42 +00:00

Summary

Readers can now add a book by hand when Open Library has no usable match, and correct the details of books they added this way. This covers "Manual book creation/corrections" from docs/EXPLORATION_IDEAS.md. It does not add an override layer for catalogue books; "Metadata corrections" stays in "Maybe later".

Entry points

  • Library → Add book manually (next to "Import from Goodreads"). The form has title, subtitle, authors, language, first published year, ISBNs and cover URL, plus list checkboxes. To read is checked by default. On a list page, that list is preselected: a custom list is checked alongside To read, a status list replaces To read.
  • Edit details on the card of a manually added book uses the same form, prefilled.
  • Goodreads import review → Create manually: the form is prefilled with the CSV row's title, authors, ISBNs and year. The created book is then imported like a confirmed match, so it gets the Goodreads reading status and shelves.

Decisions

  • Identity: a manual book is a normal library_book row whose work_id is manual:<uuid>. The uuid is the row's own id. Manual books are recognised by the prefix (isManualBook()), so there is no separate flag. These IDs never collide with Open Library keys, and the existing (user, work, language) uniqueness still holds. A DB check enforces work_id like 'manual:%' ⇔ source_url is null. I didn't change the deduplication or identity of Open Library books.
  • Schema (migration 0010): adds an isbns text[] default '{}' column and makes source_url nullable (only manual books have none). The subtitle column is the one master added in #4. BookSearchResult gets optional isbns, and sourceUrl becomes string | null. toBookSearchResult only sends isbns when set, so re-saving a catalogue book still passes the strict save payload.
  • Editable fields: title, subtitle, authors (one per line, so names like "King, Jr." keep their comma), language (or unknown), year, ISBN-10/13 (checksum-validated and normalized), and an https:// cover URL. Series, ratings and author IDs are left out.
  • Permissions: PUT /api/library/books/:id/metadata only updates rows that belong to the user and have a manual: ID. Catalogue books return 404.
  • Lists, status, bulk edit: these work unchanged because they key on the library row id. "Edit lists" uses master's membership PUT for saved books.
  • Imports: POST /api/library/imports/:id/items/:itemId/manual holds the import lease, inserts the manual book, then calls the existing finishItem/mergeImportedBook. A repeat import reuses the manual book through the earlier confirmed Goodreads row, the same way it does for catalogue matches. Imports never change a manual book's details; they only merge status and shelves. docs/goodreads-import.md is updated.
  • Recommendations: the feed now also skips rows that match a saved book's title and authors when the row has an Open Library work ID, so manual books are excluded too.
  • Card: shows ISBNs when present. Manual books show "Added manually" instead of the Open Library link.

Verification

  • pnpm lint-full passes on every commit.
  • Tested in the browser against a cloned dev DB:
    • created a manual book from a custom list page (To read and the list preselected), with ISBN validation errors and normalization;
    • created one with status Reading and a language picked in the combobox;
    • edited details (title, authors, year, ISBN, cleared subtitle);
    • "Edit lists" on a manual book;
    • the import flow: "Create manually" prefilled from the CSV, then imported with the Goodreads status;
    • re-uploading a CSV with the same Goodreads row reused the manual book (status kept, new shelf added).
  • API checks: editing a catalogue book's metadata returns 404, an http:// cover returns 400, and /api/recommendations still returns 200 with manual books saved.

Demo

demo

Download the demo video (50 s, sped up 1.8x): add a book manually with a reading status and language, edit its details, then create an unmatched Goodreads row manually from the import review.

## Summary Readers can now add a book by hand when Open Library has no usable match, and correct the details of books they added this way. This covers "Manual book creation/corrections" from `docs/EXPLORATION_IDEAS.md`. It does **not** add an override layer for catalogue books; "Metadata corrections" stays in "Maybe later". ### Entry points - **Library → Add book manually** (next to "Import from Goodreads"). The form has title, subtitle, authors, language, first published year, ISBNs and cover URL, plus list checkboxes. To read is checked by default. On a list page, that list is preselected: a custom list is checked alongside To read, a status list replaces To read. - **Edit details** on the card of a manually added book uses the same form, prefilled. - **Goodreads import review → Create manually**: the form is prefilled with the CSV row's title, authors, ISBNs and year. The created book is then imported like a confirmed match, so it gets the Goodreads reading status and shelves. ## Decisions - **Identity:** a manual book is a normal `library_book` row whose `work_id` is `manual:<uuid>`. The uuid is the row's own id. Manual books are recognised by the prefix (`isManualBook()`), so there is no separate flag. These IDs never collide with Open Library keys, and the existing `(user, work, language)` uniqueness still holds. A DB check enforces `work_id like 'manual:%'` ⇔ `source_url is null`. I didn't change the deduplication or identity of Open Library books. - **Schema (migration 0010):** adds an `isbns text[] default '{}'` column and makes `source_url` nullable (only manual books have none). The `subtitle` column is the one master added in #4. `BookSearchResult` gets optional `isbns`, and `sourceUrl` becomes `string | null`. `toBookSearchResult` only sends `isbns` when set, so re-saving a catalogue book still passes the strict save payload. - **Editable fields:** title, subtitle, authors (one per line, so names like "King, Jr." keep their comma), language (or unknown), year, ISBN-10/13 (checksum-validated and normalized), and an `https://` cover URL. Series, ratings and author IDs are left out. - **Permissions:** `PUT /api/library/books/:id/metadata` only updates rows that belong to the user **and** have a `manual:` ID. Catalogue books return 404. - **Lists, status, bulk edit:** these work unchanged because they key on the library row id. "Edit lists" uses master's membership `PUT` for saved books. - **Imports:** `POST /api/library/imports/:id/items/:itemId/manual` holds the import lease, inserts the manual book, then calls the existing `finishItem`/`mergeImportedBook`. A repeat import reuses the manual book through the earlier confirmed Goodreads row, the same way it does for catalogue matches. Imports never change a manual book's details; they only merge status and shelves. `docs/goodreads-import.md` is updated. - **Recommendations:** the feed now also skips rows that match a saved book's title and authors when the row has an Open Library work ID, so manual books are excluded too. - **Card:** shows ISBNs when present. Manual books show "Added manually" instead of the Open Library link. ## Verification - `pnpm lint-full` passes on every commit. - Tested in the browser against a cloned dev DB: - created a manual book from a custom list page (To read and the list preselected), with ISBN validation errors and normalization; - created one with status Reading and a language picked in the combobox; - edited details (title, authors, year, ISBN, cleared subtitle); - "Edit lists" on a manual book; - the import flow: "Create manually" prefilled from the CSV, then imported with the Goodreads status; - re-uploading a CSV with the same Goodreads row reused the manual book (status kept, new shelf added). - API checks: editing a catalogue book's metadata returns 404, an `http://` cover returns 400, and `/api/recommendations` still returns 200 with manual books saved. ## Demo ![demo](https://forgejo.chrispaganon.com/attachments/e80e9b93-5e0c-4a9e-a5b5-1968ec9fb88c) [Download the demo video (50 s, sped up 1.8x)](https://forgejo.chrispaganon.com/attachments/e80e9b93-5e0c-4a9e-a5b5-1968ec9fb88c): add a book manually with a reading status and language, edit its details, then create an unmatched Goodreads row manually from the import review.
Author
Owner

Reviewed the seven commits on feat/manual-books from git merge-base origin/master HEAD, excluding the unrelated changes subsequently merged into master. pnpm lint-full passes.

Important — fix before merge

  1. [P2] Preserve commas inside author names when opening/saving the manual form. shared/utils/manual-book.ts:44,58 joins the author array with commas and then splits on every comma. For example, a valid Goodreads primary author Martin Luther King, Jr. is preserved as one author by server/utils/goodreads-csv.ts, but submitting the prefilled manual form changes it into two authors, Martin Luther King and Jr.. An author supplied through the manual API suffers the same corruption on a later unrelated edit through the UI. This changes author links and title/author recommendation matching, even though the displayed joined text looks unchanged. Use a representation that round-trips individual names, such as separate author inputs or one author per line.

  2. [P2] Keep the submitted publication year authoritative for manual books. server/utils/library-import.ts:199-200 inserts the submitted metadata and immediately passes it through finishItem/mergeImportedBook. The latter's fallback at line 59 replaces a deliberately submitted null year with the original CSV year. Reproduction: review a row with a publication year, choose Create manually, clear First published, and submit; the book still has the CSV year. Clearing it later through Edit details also gets undone when the same CSV is uploaded again and its confirmed manual identity is reused. Preserve explicit manual metadata while merging Goodreads shelves/status, including an intentionally unknown year.

Pre-existing — optional follow-up

  1. [P2] Saved title/author matches do not exclude recommendations with an Open Library work ID. server/utils/recommendations.ts:34,38-39 adds saved title/author hashes to excluded, but tests only row.workId whenever present. A manual book and a trending/award recommendation with identical title and authors therefore remain in the feed together: the saved manual:<uuid> cannot equal the recommendation's Open Library ID, and its matching title/author hash is never checked. This filtering limitation predates the PR (it also affects distinct Open Library records for the same title/authors), but manual identities make it unavoidable for these sources. Consider checking the normalized title/author key as well as the work ID before grouping.

Nit picks / security

No findings. The new routes require authentication and scope mutations to the owner; the normal save schema rejects manual IDs. Manual cover URLs require HTTPS and are rendered in a plain browser image, with no server-side fetch. I found no additional upstream requests introduced by these changes.

Reviewed the seven commits on `feat/manual-books` from `git merge-base origin/master HEAD`, excluding the unrelated changes subsequently merged into master. `pnpm lint-full` passes. ### Important — fix before merge 1. **[P2] Preserve commas inside author names when opening/saving the manual form.** `shared/utils/manual-book.ts:44,58` joins the author array with commas and then splits on every comma. For example, a valid Goodreads primary author `Martin Luther King, Jr.` is preserved as one author by `server/utils/goodreads-csv.ts`, but submitting the prefilled manual form changes it into two authors, `Martin Luther King` and `Jr.`. An author supplied through the manual API suffers the same corruption on a later unrelated edit through the UI. This changes author links and title/author recommendation matching, even though the displayed joined text looks unchanged. Use a representation that round-trips individual names, such as separate author inputs or one author per line. 2. **[P2] Keep the submitted publication year authoritative for manual books.** `server/utils/library-import.ts:199-200` inserts the submitted metadata and immediately passes it through `finishItem`/`mergeImportedBook`. The latter's fallback at line 59 replaces a deliberately submitted null year with the original CSV year. Reproduction: review a row with a publication year, choose Create manually, clear First published, and submit; the book still has the CSV year. Clearing it later through Edit details also gets undone when the same CSV is uploaded again and its confirmed manual identity is reused. Preserve explicit manual metadata while merging Goodreads shelves/status, including an intentionally unknown year. ### Pre-existing — optional follow-up 3. **[P2] Saved title/author matches do not exclude recommendations with an Open Library work ID.** `server/utils/recommendations.ts:34,38-39` adds saved title/author hashes to `excluded`, but tests only `row.workId` whenever present. A manual book and a trending/award recommendation with identical title and authors therefore remain in the feed together: the saved `manual:<uuid>` cannot equal the recommendation's Open Library ID, and its matching title/author hash is never checked. This filtering limitation predates the PR (it also affects distinct Open Library records for the same title/authors), but manual identities make it unavoidable for these sources. Consider checking the normalized title/author key as well as the work ID before grouping. ### Nit picks / security No findings. The new routes require authentication and scope mutations to the owner; the normal save schema rejects manual IDs. Manual cover URLs require HTTPS and are rendered in a plain browser image, with no server-side fetch. I found no additional upstream requests introduced by these changes.
chris-paganon force-pushed feat/manual-books from 13fb7e0e4f to d10860d489 2026-11-14 18:29:14 +00:00 Compare
Author
Owner

Thanks for the review. I fixed all three findings.

  1. Commas in author names (fixed, fix: enter manual book authors one per line to keep commas in names). The form now uses a textarea with one author per line, so names like Martin Luther King, Jr. survive both the Goodreads prefill and later edits. ISBNs stay comma separated because they never contain commas. I checked in the browser that creating and then editing a book keeps ["Martin Luther King, Jr.", "Coretta Scott King"].
  2. Cleared year restored by imports (fixed, fix(import): keep submitted metadata of manual books when merging shelves). mergeImportedBook no longer runs its "fill missing metadata" update when the saved row is a manual: book. Goodreads status and shelves are still merged. I checked both paths: "Create manually" with the year cleared stores null, and re-uploading the same CSV row (year 2014) keeps null while still adding the new shelf. The import guide now says imports never change a manual book's details.
  3. Recommendation exclusion (pre-existing, fixed since it was a small, safe change: fix(recommendations): exclude saved books by title and authors even when a work ID exists). The feed now skips a row when its own title/author key matches a saved book, even if the row has an Open Library work ID. Dismissals behave as before.

Rebase: onto master after #3, #4 and the author-pages PR.

  • library_book has a single subtitle column, master's. I dropped mine.
  • The identity is still (user, work); manual:<uuid> rows simply never collide.
  • "Edit lists" uses master's PUT-for-saved-books path, and my manual-only special case is gone.
  • I regenerated my migration as 0010_bright_prima: source_url nullable, an isbns column, and the manual/source check.
  • After a fresh DB clone, all 11 migrations apply. Every commit typechecks, pnpm lint-full passes, and a browser re-check of create and edit worked.
Thanks for the review. I fixed all three findings. 1. **Commas in author names (fixed, `fix: enter manual book authors one per line to keep commas in names`).** The form now uses a textarea with one author per line, so names like `Martin Luther King, Jr.` survive both the Goodreads prefill and later edits. ISBNs stay comma separated because they never contain commas. I checked in the browser that creating and then editing a book keeps `["Martin Luther King, Jr.", "Coretta Scott King"]`. 2. **Cleared year restored by imports (fixed, `fix(import): keep submitted metadata of manual books when merging shelves`).** `mergeImportedBook` no longer runs its "fill missing metadata" update when the saved row is a `manual:` book. Goodreads status and shelves are still merged. I checked both paths: "Create manually" with the year cleared stores `null`, and re-uploading the same CSV row (year 2014) keeps `null` while still adding the new shelf. The import guide now says imports never change a manual book's details. 3. **Recommendation exclusion (pre-existing, fixed since it was a small, safe change: `fix(recommendations): exclude saved books by title and authors even when a work ID exists`).** The feed now skips a row when its own title/author key matches a saved book, even if the row has an Open Library work ID. Dismissals behave as before. **Rebase:** onto master after #3, #4 and the author-pages PR. - `library_book` has a single `subtitle` column, master's. I dropped mine. - The identity is still `(user, work)`; `manual:<uuid>` rows simply never collide. - "Edit lists" uses master's PUT-for-saved-books path, and my manual-only special case is gone. - I regenerated my migration as `0010_bright_prima`: `source_url` nullable, an `isbns` column, and the manual/source check. - After a fresh DB clone, all 11 migrations apply. Every commit typechecks, `pnpm lint-full` passes, and a browser re-check of create and edit worked.
chris-paganon deleted branch feat/manual-books 2026-11-14 18:29:42 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
chris-paganon/chrisp-books!6
No description provided.