Skip to content

Commit ee418c5

Browse files
Add / remove spinner on pagination changes
** Why are these changes being introduced: We recently refactored how the spinner is applied and removed when changing between tabs, but neglected to be consistent when it comes to pagination changes. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/use-201 ** How does this address that need: This adds the same add/remove calls for managing the spinner to the pagination management branches of the javascript file. It elects to maintain the separate pathways for these calls, rather than trying to handle the spinner in a unified area of the event listeners. ** Document any side effects to this change: The duplication of calls, like lines 46-50 being basically the same as lines 26-30, may be seen as a code smell later. For now, though, I prefer to keep them separate like this - both for parity between these pathways and also symmetry with the .classList.add() lines at 61 and 75. It seems safer to handle the spinner only in qualified contexts, rather than risking it appearing or disappearing without that being intended.
1 parent 20ad4d3 commit ee418c5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

app/javascript/loading_spinner.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ document.addEventListener('turbo:frame-render', function(event) {
2222
if (firstResult) {
2323
firstResult.focus();
2424
}
25+
26+
// Remove the spinner now that things are ready
27+
document.getElementById('search-results').classList.remove('spinner');
28+
2529
// Clear the pending action
2630
window.pendingFocusAction = null;
2731
};
@@ -53,7 +57,12 @@ document.addEventListener('click', function(event) {
5357
// Handle pagination clicks
5458
if (clickedElement.closest('.pagination-container') ||
5559
clickedElement.matches('.first a, .previous a, .next a')) {
60+
// Throw the spinner on the search results immediately
61+
document.getElementById('search-results').classList.add('spinner');
62+
63+
// Position the window at the top of the results
5664
window.scrollTo({ top: 0, behavior: 'smooth' });
65+
5766
window.pendingFocusAction = 'pagination';
5867
}
5968

0 commit comments

Comments
 (0)