From 57a4e7927ac226a5093323484ed814ab612dd525 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 3 Aug 2023 01:51:10 +0200 Subject: [PATCH] [Glitch] Add client-side timeout on resend confirmation button Port 2f932cb2bb9add10014181d978331efcf61d30f5 to glitch-soc Signed-off-by: Claire --- .../flavours/glitch/packs/sign_up.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/app/javascript/flavours/glitch/packs/sign_up.js b/app/javascript/flavours/glitch/packs/sign_up.js index 2e675dff20..4e0af41a2e 100644 --- a/app/javascript/flavours/glitch/packs/sign_up.js +++ b/app/javascript/flavours/glitch/packs/sign_up.js @@ -13,4 +13,30 @@ ready(() => { console.error(error); }); }, 5000); + + document.querySelectorAll('.timer-button').forEach(button => { + let counter = 30; + + const container = document.createElement('span'); + + const updateCounter = () => { + container.innerText = ` (${counter})`; + }; + + updateCounter(); + + const countdown = setInterval(() => { + counter--; + + if (counter === 0) { + button.disabled = false; + button.removeChild(container); + clearInterval(countdown); + } else { + updateCounter(); + } + }, 1000); + + button.appendChild(container); + }); });