Replace the My Book Notes modal with ol-dialog
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)
How to find it
- Log in and open any edition page, e.g.
http://localhost:8080/books/OL6M. - In the sidebar links (next to Review and Share), click Notes. It appears on both desktop and mobile.
- 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 fromopenlibrary/templates/type/edition/modal_links.html - JS:
initNotesModalinopenlibrary/plugins/openlibrary/js/modals/index.js, wired up injs/main.js- Save and delete POST to
/works/<id>/notes.jsonvia$.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.
- Save and delete POST to
- 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 (considerfullscreen-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). - [ ]
fetchreplaces$.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.
Context
- Current markup/JS confirmed as described:
openlibrary/macros/NotesModal.html(rendered fromopenlibrary/templates/type/edition/modal_links.html) andinitNotesModal/addNotesModalButtonListenersinopenlibrary/plugins/openlibrary/js/modals/index.js—$.ajax,confirm(), andshowToast()(a local wrapper around the legacyFadingToast, line 190) all check out. - Worth flagging for the assignee: the
.delete-note-buttonclass and theshowToast()helper inmodals/index.jsare shared withaddNotesPageButtonListeners(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 inmain.js#L240-L256(.notes-modal-linkvs.note-page-buttons), so they don't run on the same page today, but a rewrite that renames/removes.delete-note-buttonor the sharedshowToast()without checkingaddNotesPageButtonListenersfirst could silently break the notes page. - The Review modal (
openlibrary/macros/ObservationsModal.html) is confirmed still on the same legacy colorbox/floaterAddpattern, consistent with it being called out as out of scope here. - The referenced components and docs all exist as described:
OlDialog.js(supportswidthandfullscreen-on-mobile),OLButton.js,OlToastRegion.js, the "Delete this list?" confirmation example inopenlibrary/templates/design/components/dialog.html.jinja, anddocs/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-buttonclass andshowToast()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.
Hi @lokesh, I would like to work on this issue. Could you please assign this issue to me?
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.
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()inOlToastRegion.jsso 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?