9409/feat/preserve patron intent - #12764
Conversation
Adds global Javascript handlers, cookie management, and template logic to capture unauthenticated user intent and auto-resume it after login via a banner.
Applies intent tracking to modal links and star ratings. Intercepts star rating actions for logged out users to navigate to the login page.
Injects intent persistence attributes into the primary action button for reading logs in the My Books dropper.
Updates Follow, Borrow, and Join Waitlist buttons to capture unauthenticated user intent, prompting the action to automatically resume after login.
Refactors pending action banner to strictly use semantic CSS tokens from the design system rather than hard-coding HSL values, ensuring consistency across themes.
for more information, see https://pre-commit.ci
|
Thanks for this pull request, @Sadashii. π€ Copilot has been assigned for an initial review. The linked issue #9409 has been triaged (Priority 2) but does not yet have an assignee. A reviewer must first be assigned. There are currently 16 open PRs of equal or higher priority ahead of yours. Possible improvements for this PR
PR triage checklist (maintainers / Pam)
Note This comment was automatically generated by Pam, Open Library's Project AI Manager, on behalf of @mekarpeles. Pam is designed to provide status visibility, perform basic project management functions and relevant codebase research, and provide actionable feedback so contributors aren't left waiting. |
There was a problem hiding this comment.
Pull request overview
This PR adds a login-intent persistence flow so unauthenticated patrons can resume protected actions after authenticating.
Changes:
- Adds intent metadata to several protected UI controls and queues pending actions in a cookie.
- Adds post-login banner rendering/parsing for pending actions.
- Adds styling and i18n strings for the pending-action banner.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
static/css/components/mybooks-details.css |
Styles the pending-action banner. |
openlibrary/templates/type/edition/modal_links.html |
Adds intent metadata to review/notes modal links. |
openlibrary/templates/site/banner.html |
Adjusts dismissible banner cookie display logic. |
openlibrary/templates/my_books/primary_action.html |
Adds intent metadata to My Books primary/list actions. |
openlibrary/templates/my_books/dropper.html |
Passes book title into primary action rendering. |
openlibrary/templates/account/view.html |
Renders pending-action banner on account pages. |
openlibrary/plugins/upstream/utils.py |
Adds helper for intent data attributes. |
openlibrary/plugins/upstream/mybooks.py |
Parses pending-action cookie and builds banner HTML. |
openlibrary/plugins/openlibrary/js/utils.js |
Adds cookie queueing helper. |
openlibrary/plugins/openlibrary/js/star-ratings/index.js |
Redirects unauthenticated rating submissions to login. |
openlibrary/plugins/openlibrary/js/index.js |
Adds global intent click handler and auto-resume logic. |
openlibrary/macros/StarRatings.html |
Adds intent metadata to star rating labels. |
openlibrary/macros/ReadButton.html |
Adds intent metadata for unauthenticated borrow buttons. |
openlibrary/macros/LoanStatus.html |
Passes book title into loan actions and annotates waitlist. |
openlibrary/macros/Follow.html |
Adds intent metadata to follow controls. |
openlibrary/i18n/messages.pot |
Adds extracted strings for new intent/banner text. |
β¦i/openlibrary into 9409/feat/preserve-patron-intent
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
β¦i/openlibrary into 9409/feat/preserve-patron-intent
β¦ction test primary_action.html: logged-out users had data-action="Add to List" but after login the same button renders as data-action="Want to Read". The resume script matches by data-action, so the intent was never found. Use "Want to Read" as the stable key in both states so the post-login resume click works. utils.test.js: the URL-encoding test had a copy-paste bug β expectedData had name: 'Dune' and type: 'book' that didn't match the actual queueAction call args, causing the test to always fail.
β¦, remove auto-click - Banner message: 'You were trying to ... Click the link to resume.' β 'Continue <action> the <type> <name>.' (consistent imperative phrasing) - Star rating actions: 'Rate N star(s)' β 'leaving a N star review for' (gerund form fits 'Continue <action> the book <title>.' template); also move title+actions outside the loop (computed once per render) - modal_links.html: 'Add a review' β 'reviewing', 'Add a note' β 'adding notes to' - Remove auto-click DOMContentLoaded handler and __modalsLoaded flag; the banner link is sufficient for resuming intent post-login - Simplify account/view.html: remove sessionStorage.setItem (dead code without the auto-click); clean up cookie-clear on banner link click
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
|
@mekarpeles With the latest changes, if we hardcode 'book' it will give an incorrect message if the patron action was follow an author, as it will say 'follow the book (authorname)'. The page_type var dealt with this quirk. |
β¦e-patron-intent # Conflicts: # openlibrary/plugins/upstream/utils.py
for more information, see https://pre-commit.ci
β¦' into 9409/feat/preserve-patron-intent
|
Worth noting that clicking "continue to give 4 star review for ..." doesn't actually perform the star rating. This is something we may want to improve |


Closes #9409
[feature]
This PR introduces an Authentication Action Persistence mechanism across Open Library. It standardizes the workflow for unauthenticated users when they interact with protected features (such as Rating, Borrowing, Adding to lists, Joining Waitlist, or Following). Instead of losing their context after being redirected to the login page, their intent (Action, Book Name, and URL) is stored securely in a cookie. After a successful login, a dynamic banner prompts them to automatically resume their pending action, providing a seamless user experience.
Technical
data-login-action,data-login-book, anddata-login-urldata attributes across various interactive components (macros/Follow.html,macros/LoanStatus.html,macros/ReadButton.html,macros/StarRatings.html,modal_links.html, and My Books droppers).openlibrary/plugins/openlibrary/js/index.jsandutils.js) that intercepts clicks on these protected elements when unauthenticated, serializes the action context into a cookie, and routes the user to the login page.templates/account/view.htmlandtemplates/site/banner.htmlto read the intent cookie post-login and render a "Resume Action" banner.mybooks.pyandutils.pyto parse the intent cookie and provide the context variables to the frontend.mybooks-details.cssto strictly use semantic CSS tokens from the design system for the pending action banner, rather than hard-coded HSL values, ensuring consistency across light/dark themes.Testing
Screenshot
Stakeholders
@mekarpeles
(Please tag the issue lead or relevant maintainers here)