Patron exports: disable buttons, show “Downloading…”, prevent duplicates, restore on completion#11342
Merged
jimchamp merged 2 commits intointernetarchive:masterfrom Dec 2, 2025
Conversation
for more information, see https://pre-commit.ci
jimchamp
approved these changes
Dec 2, 2025
Collaborator
jimchamp
left a comment
There was a problem hiding this comment.
Thanks @isaactony, and sorry for the massive delay.
This is working as expected, but managing uploads via JS is much more complicated than I initially expected. It's highly likely that we'll roll back the JS upload management, and simply disable these buttons when they are pressed.
| } | ||
|
|
||
| // Enhance patron export buttons on /account/import | ||
| if (location.pathname === '/account/import') { |
Collaborator
There was a problem hiding this comment.
We typically query for elements that need hydration, then import and initialize if such elements are found on the page.
This will break if we ever move the export options to a new page.
Comment on lines
+22
to
+24
| buttonElement.value = 'Downloading...'; | ||
| } else { | ||
| buttonElement.textContent = 'Downloading...'; |
Collaborator
There was a problem hiding this comment.
These strings are not localized, and will appear as English despite the patron's language settings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Duration. Fixes #11341
Closes #11341
Achieves: [fix]
Prevents multiple concurrent patron export requests and adds clear in-progress feedback on /account/import.
Adds openlibrary/plugins/openlibrary/js/patron_exports.js
On export form submit, disables the clicked button, sets aria-disabled, swaps CSS classes to cta-btn--unavailable cta-btn--unavailable--load, and changes text to “Downloading…”.
Uses fetch to request /account/export?type=..., reads the CSV as a Blob, and triggers download via an object URL.
Detects completion and restores the button to its original state.
Enforces a minimum 800ms visible loading period to make the state change perceptible for very fast downloads.
Wires the module in openlibrary/plugins/openlibrary/js/index.js to load only on the /account/import page.
No backend or API changes were required.
Testing
Build front-end assets:
docker compose run --rm home npm install --no-audit
docker compose run --rm home npm run build-assets:js
Run the site:
docker compose up -d
Visit http://localhost:8080/
Reproduce the fix:
Log in and navigate to /account/import
Click any “Download (.csv format)” button
Observe:

Button text changes to “Downloading…”
Button becomes disabled (greyed out)
Only one request is triggered
After download completes, button reverts to normal
@jimchamp