Skip to content

Commit

Permalink
Merge pull request #392 from freelawproject/feat-add-spinner-to-view-…
Browse files Browse the repository at this point in the history
…and-recap-btn

feat(spinner): Adds spinner next to the custom button for filer accounts
  • Loading branch information
mlissner authored Aug 31, 2024
2 parents 6592874 + 391288e commit 26e5f85
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
The following changes are not yet released, but are code complete:

Features:
- None yet
- Improve the user experience of the file account button by applying a custom cursor and adding a loading spinner next to it while the extension load the PDF document ([392](https://github.com/freelawproject/recap-chrome/pull/392)).

Changes:
- None yet
Expand Down
5 changes: 1 addition & 4 deletions src/action_button.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,7 @@ const recapActionsButton = (court, pacerCaseId) => {
mainDiv.classList.add('btn-group');
mainDiv.setAttribute('id', 'recap-action-button');

const spinner = document.createElement('i');
spinner.classList.add('fa', 'fa-spinner', 'fa-spin');
spinner.setAttribute('id', 'recap-button-spinner');
spinner.classList.add('recap-btn-spinner-hidden');
const spinner = createRecapSpinner();

const mainButton = document.createElement('a');
mainButton.classList.add('btn', 'btn-primary', 'dropdown-toggle');
Expand Down
7 changes: 7 additions & 0 deletions src/appellate/appellate.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,15 +1038,22 @@ AppellateDelegate.prototype.handleSingleDocumentPageView = async function () {
let button = createRecapButtonForFilers(
'Accept Charges and RECAP Document'
);
let spinner = createRecapSpinner();
button.addEventListener('click', (event) => {
event.preventDefault();
let form = event.target.parentNode;
form.id = 'form' + new Date().getTime();

let spinner = document.getElementById('recap-button-spinner');
if (spinner) spinner.classList.remove('recap-btn-spinner-hidden');

window.postMessage({ id: form.id }, '*');
});

let form = document.querySelector('form');
form.append(button);
form.append(document.createTextNode('\u00A0'));
form.append(spinner);
} else {
await overwriteFormSubmitMethod();
}
Expand Down
1 change: 1 addition & 0 deletions src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ footer #version {
}

.recap-bttn-for-filers {
cursor: pointer;
margin-left: 5px;
border-radius: 3px;
border-style: solid;
Expand Down
10 changes: 7 additions & 3 deletions src/content_delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ ContentDelegate.prototype.handleSingleDocumentPageView = async function () {
// Create a new button for filers accounts and add onclick
// event listener to intercept navigation to the PDF document
let button = createRecapButtonForFilers('View and RECAP Document');
let spinner = createRecapSpinner();
button.addEventListener('click', async (event) => {
// Get the button element that was actually clicked (event.target)
let button = event.target;
Expand All @@ -547,11 +548,16 @@ ContentDelegate.prototype.handleSingleDocumentPageView = async function () {
// service. This attribute indicates that the user specifically clicked
// this custom button, triggering the upload process.
button.setAttribute('clicked','');
let spinner = document.getElementById('recap-button-spinner');
if (spinner) spinner.classList.remove('recap-btn-spinner-hidden');

return true;
});
// add the new button inside the form
let form = document.querySelector('form');
form.append(button);
form.append(document.createTextNode('\u00A0'));
form.append(spinner);
}
await overwriteFormSubmitMethod();

Expand Down Expand Up @@ -694,9 +700,7 @@ ContentDelegate.prototype.onDownloadAllSubmit = async function (event) {
loadingMessageWrapper.setAttribute('id', 'loading-message');
loadingMessageWrapper.style.textAlign = 'center';

const spinner = document.createElement('i');
spinner.classList.add('fa', 'fa-spinner', 'fa-spin');
spinner.setAttribute('id', 'recap-button-spinner');
const spinner = createRecapSpinner(false);

let spanText = document.createElement('span');
spanText.style.fontFamily = 'helvetica,arial,serif';
Expand Down
16 changes: 16 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,19 @@ function createRecapButtonForFilers(description) {
button.classList.add('recap-bttn-for-filers', 'btn-primary');
return button;
}

// Creates a spinner element to be used in the recap button.
//
// **Arguments:**
// - `hidden` (bool): Whether the spinner should be initially hidden.
//
// **Returns:**
// - The created spinner element.
function createRecapSpinner(hidden = true) {
const spinner = document.createElement('i');
spinner.classList.add('fa', 'fa-spinner', 'fa-spin');
spinner.setAttribute('id', 'recap-button-spinner');
if (hidden) spinner.classList.add('recap-btn-spinner-hidden');

return spinner;
}

0 comments on commit 26e5f85

Please sign in to comment.