Skip to content

Patron exports: disable buttons, show “Downloading…”, prevent duplicates, restore on completion#11342

Merged
jimchamp merged 2 commits intointernetarchive:masterfrom
isaactony:123/feature/patron-exports-disabled
Dec 2, 2025
Merged

Patron exports: disable buttons, show “Downloading…”, prevent duplicates, restore on completion#11342
jimchamp merged 2 commits intointernetarchive:masterfrom
isaactony:123/feature/patron-exports-disabled

Conversation

@isaactony
Copy link
Copy Markdown
Contributor

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
image

After download completes, button reverts to normal

@jimchamp

Copy link
Copy Markdown
Collaborator

@jimchamp jimchamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...';
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These strings are not localized, and will appear as English despite the patron's language settings.

@jimchamp jimchamp merged commit c8cc3be into internetarchive:master Dec 2, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Download button for patron exports should be disabled on click

2 participants