From fcb7062200c9301cf6a19c791f465b5ba44f6775 Mon Sep 17 00:00:00 2001 From: PouyaMohseni Date: Sun, 28 Dec 2025 16:09:16 -0500 Subject: [PATCH] fix: prevent duplicate publish requests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - disabling confirm button - show `Saving…` during publish resolves #479 --- web-app/frontend/src/instruments/AddName.ts | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/web-app/frontend/src/instruments/AddName.ts b/web-app/frontend/src/instruments/AddName.ts index 28a971f6..92c744d5 100644 --- a/web-app/frontend/src/instruments/AddName.ts +++ b/web-app/frontend/src/instruments/AddName.ts @@ -7,6 +7,7 @@ declare const languages: WikidataLanguage[]; let nameValidator: NameValidator; let addNameManager: AddNameManager; +let isPublishing = false; // Handle modal show event - populate instrument data const addNameModal = document.getElementById('addNameModal'); @@ -69,6 +70,17 @@ document document .getElementById('confirmPublishBtn') .addEventListener('click', function () { + if (isPublishing) return; + isPublishing = true; + + const confirmBtn = document.getElementById( + 'confirmPublishBtn', + ) as HTMLButtonElement; + + // Disable button and rename it + confirmBtn.disabled = true; + confirmBtn.textContent = 'Saving…'; + const wikidataId = document .getElementById('instrumentWikidataIdInModal') .textContent.trim(); @@ -133,9 +145,19 @@ document window.location.reload(); } else { alert('Error: ' + data.message); + + // Restore state on failure + isPublishing = false; + confirmBtn.disabled = false; + confirmBtn.textContent = 'Confirm'; } }) .catch((error) => { alert('An error occurred while publishing: ' + error.message); + + // Restore state on failure + isPublishing = false; + confirmBtn.disabled = false; + confirmBtn.textContent = 'Confirm'; }); });