Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
@import "partials/_search";
@import "partials/_shared";
@import "partials/_results";
@import "partials/_loading_spinner";
@import "partials/_typography";
@import "partials/_suggestion-panel";
50 changes: 50 additions & 0 deletions app/assets/stylesheets/partials/_loading_spinner.scss
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;
}
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/partials/_results.scss
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@
font-size: 1.8rem;
line-height: 1.1;
}
}
}
3 changes: 2 additions & 1 deletion app/javascript/application.js
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;
Copy link
Member

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

Copy link
Contributor Author

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. :)

23 changes: 23 additions & 0 deletions app/javascript/loading_spinner.js
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';
}
});
2 changes: 1 addition & 1 deletion app/views/search/results.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<%= render(partial: 'trigger_tacos') if tacos_enabled? %>

<%= turbo_frame_tag "search-results" do %>
<%= turbo_frame_tag "search-results", data: { turbo_action: "advance" } do %>
<div class="layout-3q1q layout-band top-space">
<main id="results" class="col3q wrap-results">
<% if @show_primo_continuation %>
Expand Down
1 change: 1 addition & 0 deletions config/importmap.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Pin npm packages by running ./bin/importmap

pin "application", preload: true
pin "loading_spinner", preload: true
pin "@hotwired/turbo-rails", to: "turbo.min.js", preload: true
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true
Expand Down