From bd29dd1ac3e7ac27658b2f4123c0d1ab8ccdd94c Mon Sep 17 00:00:00 2001 From: alonsofabila-dev Date: Fri, 22 Nov 2024 03:14:26 -0600 Subject: [PATCH] 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> --- src/main/resources/static/js/downloader.js | 24 +++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/resources/static/js/downloader.js b/src/main/resources/static/js/downloader.js index e828bb86..5433d872 100644 --- a/src/main/resources/static/js/downloader.js +++ b/src/main/resources/static/js/downloader.js @@ -34,6 +34,12 @@ const url = this.action; const files = $("#fileInput-input")[0].files; 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 for (let [key, value] of formData.entries()) { @@ -42,14 +48,10 @@ } } const override = $("#override").val() || ""; - const originalButtonText = $("#submitBtn").text(); - $("#submitBtn").text("Processing..."); console.log(override); // Set a timeout to show the game button if operation takes more than 5 seconds const timeoutId = setTimeout(() => { - var boredWaiting = localStorage.getItem("boredWaiting") || "disabled"; - const showGameBtn = document.getElementById("show-game-btn"); if (boredWaiting === "enabled" && showGameBtn) { showGameBtn.style.display = "block"; showGameBtn.parentNode.insertBefore(document.createElement('br'), showGameBtn.nextSibling); @@ -57,6 +59,9 @@ }, 5000); try { + submitButton.textContent = "Processing..."; + submitButton.disabled = true; + if (remoteCall === true) { if (override === "multi" || (!multipleInputsForSingleRequest && files.length > 1 && override !== "single")) { await submitMultiPdfForm(url, files); @@ -65,12 +70,15 @@ } } + clearFileInput(); 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 - const boredWaiting = localStorage.getItem("boredWaiting") || "disabled"; const gameDialog = document.getElementById('game-container-wrapper'); if (boredWaiting === "enabled" && gameDialog && gameDialog.open) { // Display a green banner at the bottom of the screen saying "Download complete" @@ -89,8 +97,10 @@ } catch (error) { clearFileInput(); clearTimeout(timeoutId); + showGameBtn.style.display = "none"; + submitButton.textContent = originalButtonText; + submitButton.disabled = false; handleDownloadError(error); - $("#submitBtn").text(originalButtonText); console.error(error); } });