Bored waiting button doesnt remove itself after processing (#2079) (#2235)

Fix: Bored waiting button doesnt remove itself after processing (#2079)

hide bored waiting? button after request handling both success and error cases to properly hide the button.

Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
This commit is contained in:
alonsofabila-dev 2024-11-22 03:14:26 -06:00 committed by GitHub
parent 6d3f14375e
commit bd29dd1ac3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -34,6 +34,12 @@
const url = this.action; const url = this.action;
const files = $("#fileInput-input")[0].files; const files = $("#fileInput-input")[0].files;
const formData = new FormData(this); const formData = new FormData(this);
const submitButton = document.getElementById("submitBtn");
const showGameBtn = document.getElementById("show-game-btn");
const originalButtonText = submitButton.textContent;
var boredWaiting = localStorage.getItem("boredWaiting") || "disabled";
showGameBtn.style.display = "none";
// Remove empty file entries // Remove empty file entries
for (let [key, value] of formData.entries()) { for (let [key, value] of formData.entries()) {
@ -42,14 +48,10 @@
} }
} }
const override = $("#override").val() || ""; const override = $("#override").val() || "";
const originalButtonText = $("#submitBtn").text();
$("#submitBtn").text("Processing...");
console.log(override); console.log(override);
// Set a timeout to show the game button if operation takes more than 5 seconds // Set a timeout to show the game button if operation takes more than 5 seconds
const timeoutId = setTimeout(() => { const timeoutId = setTimeout(() => {
var boredWaiting = localStorage.getItem("boredWaiting") || "disabled";
const showGameBtn = document.getElementById("show-game-btn");
if (boredWaiting === "enabled" && showGameBtn) { if (boredWaiting === "enabled" && showGameBtn) {
showGameBtn.style.display = "block"; showGameBtn.style.display = "block";
showGameBtn.parentNode.insertBefore(document.createElement('br'), showGameBtn.nextSibling); showGameBtn.parentNode.insertBefore(document.createElement('br'), showGameBtn.nextSibling);
@ -57,6 +59,9 @@
}, 5000); }, 5000);
try { try {
submitButton.textContent = "Processing...";
submitButton.disabled = true;
if (remoteCall === true) { if (remoteCall === true) {
if (override === "multi" || (!multipleInputsForSingleRequest && files.length > 1 && override !== "single")) { if (override === "multi" || (!multipleInputsForSingleRequest && files.length > 1 && override !== "single")) {
await submitMultiPdfForm(url, files); await submitMultiPdfForm(url, files);
@ -65,12 +70,15 @@
} }
} }
clearFileInput(); clearFileInput();
clearTimeout(timeoutId); clearTimeout(timeoutId);
$("#submitBtn").text(originalButtonText); showGameBtn.style.display = "none";
showGameBtn.style.marginTop = "";
submitButton.textContent = originalButtonText;
submitButton.disabled = false;
// After process finishes, check for boredWaiting and gameDialog open status // After process finishes, check for boredWaiting and gameDialog open status
const boredWaiting = localStorage.getItem("boredWaiting") || "disabled";
const gameDialog = document.getElementById('game-container-wrapper'); const gameDialog = document.getElementById('game-container-wrapper');
if (boredWaiting === "enabled" && gameDialog && gameDialog.open) { if (boredWaiting === "enabled" && gameDialog && gameDialog.open) {
// Display a green banner at the bottom of the screen saying "Download complete" // Display a green banner at the bottom of the screen saying "Download complete"
@ -89,8 +97,10 @@
} catch (error) { } catch (error) {
clearFileInput(); clearFileInput();
clearTimeout(timeoutId); clearTimeout(timeoutId);
showGameBtn.style.display = "none";
submitButton.textContent = originalButtonText;
submitButton.disabled = false;
handleDownloadError(error); handleDownloadError(error);
$("#submitBtn").text(originalButtonText);
console.error(error); console.error(error);
} }
}); });