openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Replace the My Book Notes modal with ol-dialog

Open lokesh opened this issue 2 months ago • 4 comments

Summary

On a book page, the Notes link in the sidebar opens the My Book Notes modal, which is built on the old jQuery colorbox. Rebuild it on <ol-dialog>, and use the rest of our web components inside it: <ol-button> for the actions, showToast() / <ol-toast> for feedback, and an <ol-dialog> confirmation instead of the browser's confirm().

Related: #13651 and #13652 (the same change for the Wikipedia citation dialog and the Share modal)

Image

How to find it

  1. Log in and open any edition page, e.g. http://localhost:8080/books/OL6M.
  2. In the sidebar links (next to Review and Share), click Notes. It appears on both desktop and mobile.
  3. Saved notes also show up on your notes page in My Books (/people/<username>/books/notes), which is useful for checking that save and delete worked.

Current implementation

  • Markup: openlibrary/macros/NotesModal.html, rendered from openlibrary/templates/type/edition/modal_links.html
  • JS: initNotesModal in openlibrary/plugins/openlibrary/js/modals/index.js, wired up in js/main.js
    • Save and delete POST to /works/<id>/notes.json via $.ajax.
    • Delete uses confirm('Really delete this book note?').
    • Feedback uses the legacy FadingToast, and colorbox closes the modal.
    • The toast strings and the confirm string are hardcoded English and not translatable.
  • Buttons: legacy cta-btn cta-btn--delete / cta-btn--shell

Components to use

Need Component Reference
Dialog <ol-dialog label="…" width="medium"> openlibrary/components/lit/OlDialog.js; the "Form dialog" example under Dialog on the Components design page is almost exactly this UI
Save / Delete / Cancel <ol-button variant="primary" / "secondary" / "destructive"> OLButton.js, the "Variants" example under Button
Delete confirmation a second small <ol-dialog> the "Confirmation" example ("Delete this list?") under Dialog
Success/error feedback showToast() openlibrary/components/lit/OlToastRegion.js, the "Imperative use" example under Toast

Read docs/ai/design.md and docs/ai/web-components.md before starting.

Acceptance criteria

  • [ ] Clicking Notes opens an <ol-dialog> titled "My Book Notes", on both desktop and mobile (consider fullscreen-on-mobile).
  • [ ] The textarea is prefilled with the saved note, and focus lands in it when the dialog opens.
  • [ ] Save uses <ol-button variant="primary">, POSTs the note, closes the dialog and shows a success toast.
  • [ ] Delete only appears when a note exists. It uses <ol-button variant="destructive"> and asks for confirmation in an <ol-dialog>. On confirm it deletes the note, clears the textarea, hides Delete and shows a toast.
  • [ ] Failed requests show an error toast and keep the dialog open, so the note isn't lost.
  • [ ] Logged-out patrons still get the existing login redirect (notes-modal-link--redirect js-login-intent).
  • [ ] fetch replaces $.ajax, with no new jQuery.
  • [ ] Every user-facing string, including the toasts and the confirmation, is translatable (see docs/ai/i18n.md).
  • [ ] The notes colorbox wiring and legacy markup are removed. Leave the Review (ObservationsModal) modal and the My Books notes page alone; they're out of scope.
  • [ ] Keyboard works end to end: Tab stays inside the dialog, Escape closes it and focus returns to the Notes link.

lokesh avatar Sep 16 '26 22:09 lokesh

Context

  • Current markup/JS confirmed as described: openlibrary/macros/NotesModal.html (rendered from openlibrary/templates/type/edition/modal_links.html) and initNotesModal/addNotesModalButtonListeners in openlibrary/plugins/openlibrary/js/modals/index.js — $.ajax, confirm(), and showToast() (a local wrapper around the legacy FadingToast, line 190) all check out.
  • Worth flagging for the assignee: the .delete-note-button class and the showToast() helper in modals/index.js are shared with addNotesPageButtonListeners (lines 103-155), which drives the My Books notes page (openlibrary/templates/account/notes.html:62) — explicitly called out as out of scope. The two are gated on different page markers in main.js#L240-L256 (.notes-modal-link vs .note-page-buttons), so they don't run on the same page today, but a rewrite that renames/removes .delete-note-button or the shared showToast() without checking addNotesPageButtonListeners first could silently break the notes page.
  • The Review modal (openlibrary/macros/ObservationsModal.html) is confirmed still on the same legacy colorbox/floaterAdd pattern, consistent with it being called out as out of scope here.
  • The referenced components and docs all exist as described: OlDialog.js (supports width and fullscreen-on-mobile), OLButton.js, OlToastRegion.js, the "Delete this list?" confirmation example in openlibrary/templates/design/components/dialog.html.jinja, and docs/ai/design.md / docs/ai/web-components.md.
  • No existing PR or merged work found addressing this notes modal specifically; #13651 and #13652 (the sibling Wikipedia-citation and Share-modal conversions) are both still open with no linked PRs.

Issue Assessment

Open questions

  • Should the .delete-note-button class and showToast() helper be split out (e.g. dedicated notes-modal-only naming) as part of this change, or is it acceptable to leave them shared with the out-of-scope notes page since the two currently never run on the same page?
Full triage checklist
  • [x] Triage — labels look correct; Priority, Lead, and Good First Issue already set by the reporter/lead
  • [x] Problem / opportunity — clear: modernize a specific legacy jQuery/colorbox modal onto existing web components
  • [x] Scope — well-bounded to one modal; explicitly excludes the Review modal and notes page
  • [x] Justification — consistent with sibling issues #13651/#13652 and the broader UI modernization effort (#13240)
  • [x] Success & testing criteria — detailed, verifiable acceptance criteria checklist present
  • [x] Proposal & breakdown — concrete component mapping table and current-implementation notes provided
  • [x] If bug: environment & repro steps — N/A (refactor), but "How to find it" steps are given
  • [x] Risks, concerns, open questions — one shared-code risk surfaced above
  • [x] Richy context — code, docs, and related issues reviewed; no duplicate or superseding work found
  • [x] References — screenshot and docs links present

[!NOTE] This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.

openlibrary-bot avatar Sep 16 '26 22:09 openlibrary-bot

Hi @lokesh, I would like to work on this issue. Could you please assign this issue to me?

Shreya-S-Jadhav avatar Sep 17 '26 09:09 Shreya-S-Jadhav

Hey @lokesh, I’d like to contribute to this repo as I’m a beginner in open source. Could you guide me on where I can start, or let me know if there’s a channel/community I can join for guidance?

Also, if possible, could this issue be assigned to me? I’d love to work on it and contribute to the project.

MohitSAGAR11 avatar Sep 17 '26 17:09 MohitSAGAR11

Hi @lokesh — I've read through the current implementation and the component docs. Two questions before I start.

1. Calling showToast() from page JS

showToast lives in the components bundle, and OlToastRegion.js:145 calls customElements.define('ol-toast-region', …) without a guard (unlike OlDialog.js, which checks customElements.get() first). So importing it into modals/index.js would throw NotSupportedError — the failure mode docs/ai/web-components.md:355 warns about. It would also pull Lit into the page bundle and break the 7KB modals.js budget in bundlesize.config.json.

design/components/toast.html.jinja:33 already works around this with a local copy of the helper, so there's precedent.

Options as I see them:

  • (a) Mirror the helper locally in the notes module
  • (b) Add a small shared page-JS toast helper
  • (c) Guard the define() in OlToastRegion.js so it becomes importable

I'd lean towards (a) — it keeps this PR scoped to the notes modal, and (b) or (c) feel like decisions better made when #13651/#13652 land and there are three callers to design for. Happy to do either of the others if you'd prefer.

2. The shared .delete-note-button class

Following up on the bot's question: I plan to leave addNotesPageButtonListeners and account/notes.html completely untouched, and give the notes-modal delete button its own class so the two can't drift into each other. Does that match what you'd want?

MohitSAGAR11 avatar Sep 18 '26 09:09 MohitSAGAR11