-
Notifications
You must be signed in to change notification settings - Fork 0
Add loading spinner for Turbo Frame updates #264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Loading indicator for pagination (Turbo Frame updates) | ||
| // Tab navigation uses full page loads with Turbo's built-in progress bar | ||
| // https://discuss.hotwired.dev/t/show-spinner-everytime-async-frame-reloads/3483/3 | ||
| @keyframes spinner { | ||
| to { | ||
| transform: rotate(360deg); | ||
| } | ||
| } | ||
|
|
||
| // Pagination overlay when loading | ||
| [busy]:not([no-spinner]) { | ||
| position: relative; | ||
| min-height: 400px; | ||
| display: block; | ||
|
|
||
| > * { | ||
| opacity: 0.3; | ||
| } | ||
|
|
||
| // Loading text | ||
| &::before { | ||
| content: 'Loading results...'; | ||
| position: absolute; | ||
| top: 5.5rem; | ||
| left: 50%; | ||
| margin-left: -6rem; // Center the text box (12rem / 2) | ||
| width: 12rem; | ||
| font-size: $fs-small; | ||
| font-weight: $fw-semibold; | ||
| color: $color-black; | ||
| text-align: center; | ||
| z-index: 1001; | ||
| } | ||
|
|
||
| // Spinner positioned above text | ||
| &::after { | ||
| content: ''; | ||
| position: absolute; | ||
| top: 1rem; | ||
| left: 50%; | ||
| margin-left: -2rem; | ||
| width: 3rem; | ||
| height: 3rem; | ||
| border-radius: 50%; | ||
| border: 0.3rem solid $color-gray-200; | ||
| border-top-color: $color-red-500; | ||
| animation: spinner 1s linear infinite; | ||
| z-index: 1000; | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,4 +118,4 @@ | |
| font-size: 1.8rem; | ||
| line-height: 1.1; | ||
| } | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| // Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails | ||
| import "@hotwired/turbo-rails" | ||
| import "controllers" | ||
| import "loading_spinner" | ||
|
|
||
| // Show the progress bar after 200 milliseconds, not the default 500 | ||
| window.Turbo.setProgressBarDelay(200); | ||
| Turbo.config.drive.progressBarDelay = 200; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Loading spinner behavior for pagination (Turbo Frame updates) | ||
| document.addEventListener('turbo:frame-render', function(event) { | ||
| if (window.pendingFocusAction === 'pagination') { | ||
| // Focus on first result for pagination | ||
| const firstResult = document.querySelector('.results-list .result h3 a, .results-list .result .record-title a'); | ||
| if (firstResult) { | ||
| firstResult.focus(); | ||
| } | ||
| // Clear the pending action | ||
| window.pendingFocusAction = null; | ||
| } | ||
| }); | ||
|
|
||
| document.addEventListener('click', function(event) { | ||
| const clickedElement = event.target; | ||
|
|
||
| // Handle pagination clicks | ||
| if (clickedElement.closest('.pagination-container') || | ||
| clickedElement.matches('.first a, .previous a, .next a')) { | ||
| window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
| window.pendingFocusAction = 'pagination'; | ||
| } | ||
| }); |
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha, I think I opened a separate ticket for this yesterday so you can grab it, move it to the Sprint, and Done it when this merges.
https://mitlibraries.atlassian.net/browse/USE-166
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol I didn't bother mentioning it on the other PR since I knew I had it here. :)