internetarchive / internetarchive/openlibrary

Replace the My Book Notes modal with ol-dialog

Open
#13,653 3 comments 0 reactions 1 assignee Claimed by @MohitSAGAR11 View on GitHub
Good First Issue Lead: @lokesh Type: Refactor/Clean-up
Dominant language
Python
Stars
6.7k
Forks
2k
Avg merge
2d 19h
Merged PRs (30d)
138

Description

### 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 ``, and use the rest of our web components inside it: `` for the actions, `showToast()` / `` for feedback, and an `` 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//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//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 | `` | `openlibrary/components/lit/OlDialog.js`; the ["Form dialog" example](https://openlibrary.org/developers/design/components#demo-dialog-form-trigger) under [Dialog on the Components design page](https://openlibrary.org/developers/design/components#dialog) is almost exactly this UI |
| Save / Delete / Cancel | `` | `OLButton.js`, the "Variants" example under [Button](https://openlibrary.org/developers/design/components#button) |
| Delete confirmation | a second small `` | the ["Confirmation" example](https://openlibrary.org/developers/design/components#demo-dialog-confirm-trigger) ("Delete this list?") under Dialog |
| Success/error feedback | `showToast()` | `openlibrary/components/lit/OlToastRegion.js`, the "Imperative use" example under [Toast](https://openlibrary.org/developers/design/components#toast) |

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

### Acceptance criteria

- [ ] Clicking **Notes** opens an `` 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 ``, POSTs the note, closes the dialog and shows a success toast.
- [ ] **Delete** only appears when a note exists. It uses `` and asks for confirmation in an ``. 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.