From 69aa891954821e544c46f864cf742c5bab5cfee2 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 8 Jun 2026 04:51:48 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Palette:=20Add=20async=20loading?= =?UTF-8?q?=20states=20to=20authentication=20buttons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added disabled loading states with ARIA attributes to the Login, Registration, and Google Sign-In buttons using vanilla JavaScript to enhance user experience and accessibility. Co-authored-by: singhaditya21 <53948039+singhaditya21@users.noreply.github.com> --- .Jules/palette.md | 3 ++ web-demo/js/app.js | 93 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 72 insertions(+), 24 deletions(-) create mode 100644 .Jules/palette.md diff --git a/.Jules/palette.md b/.Jules/palette.md new file mode 100644 index 0000000..0756946 --- /dev/null +++ b/.Jules/palette.md @@ -0,0 +1,3 @@ +## 2026-06-08 - [Vanilla JS Form Submitter Async States] +**Learning:** When interacting with form submit events in the vanilla JavaScript frontend, use `e.submitter` to reliably capture the specific button that triggered the submission, but only access it safely inside a null-check block. Also, convert simulated async timeouts into awaitable Promises `await new Promise(r => setTimeout(r, delay))` so state cleanup logically falls into a `finally` block, ensuring the UI recovers reliably. +**Action:** Use `e.submitter` guarded by a truthy check for button state management, and refactor loose `setTimeout` mock operations into Promises to guarantee `finally` block execution for resetting UI state. diff --git a/web-demo/js/app.js b/web-demo/js/app.js index 11508de..58b0d07 100644 --- a/web-demo/js/app.js +++ b/web-demo/js/app.js @@ -65,7 +65,7 @@ class ClimaAI { setupEventListeners() { // Auth - document.getElementById('googleSignInBtn').addEventListener('click', () => this.handleGoogleSignIn()); + document.getElementById('googleSignInBtn').addEventListener('click', (e) => this.handleGoogleSignIn(e)); document.getElementById('loginForm').addEventListener('submit', (e) => this.handleLogin(e)); document.getElementById('registerForm').addEventListener('submit', (e) => this.handleRegister(e)); document.getElementById('showRegister').addEventListener('click', (e) => { @@ -144,6 +144,15 @@ class ClimaAI { e.preventDefault(); const email = document.getElementById('loginEmail').value; const password = document.getElementById('loginPassword').value; + const submitBtn = e.submitter; + let originalContent = ''; + + if (submitBtn) { + originalContent = submitBtn.innerHTML; + submitBtn.innerHTML = '⏳ Logging in...'; + submitBtn.disabled = true; + submitBtn.setAttribute('aria-busy', 'true'); + } try { this.showToast('Logging in...', 'info'); @@ -155,6 +164,12 @@ class ClimaAI { this.checkSubscription(); } catch (error) { this.showToast(error.message || 'Login failed', 'error'); + } finally { + if (submitBtn) { + submitBtn.innerHTML = originalContent; + submitBtn.disabled = false; + submitBtn.removeAttribute('aria-busy'); + } } } @@ -163,6 +178,15 @@ class ClimaAI { const name = document.getElementById('registerName').value; const email = document.getElementById('registerEmail').value; const password = document.getElementById('registerPassword').value; + const submitBtn = e.submitter; + let originalContent = ''; + + if (submitBtn) { + originalContent = submitBtn.innerHTML; + submitBtn.innerHTML = '⏳ Creating account...'; + submitBtn.disabled = true; + submitBtn.setAttribute('aria-busy', 'true'); + } try { this.showToast('Creating account...', 'info'); @@ -174,6 +198,12 @@ class ClimaAI { this.checkSubscription(); } catch (error) { this.showToast(error.message || 'Registration failed', 'error'); + } finally { + if (submitBtn) { + submitBtn.innerHTML = originalContent; + submitBtn.disabled = false; + submitBtn.removeAttribute('aria-busy'); + } } } @@ -185,7 +215,17 @@ class ClimaAI { this.showToast('Logged out successfully', 'info'); } - async handleGoogleSignIn() { + async handleGoogleSignIn(e) { + const btn = e ? e.currentTarget : null; + let originalContent = ''; + + if (btn) { + originalContent = btn.innerHTML; + btn.innerHTML = '⏳ Connecting...'; + btn.disabled = true; + btn.setAttribute('aria-busy', 'true'); + } + try { this.showToast('🔐 Signing in with Google...', 'info'); @@ -197,31 +237,36 @@ class ClimaAI { // 5. Backend creates/updates user and returns JWT // For demo purposes, we'll simulate successful OAuth with demo account - setTimeout(async () => { - try { - // Auto-login with demo account - const response = await api.login('demo@climaai.com', 'Test1234'); - this.user = response.user; - this.showToast('✅ Welcome! Signed in with Google', 'success'); - this.showScreen('homeScreen'); - this.loadWeatherData(); - this.checkSubscription(); - } catch (error) { - this.showToast('Google Sign-In succeeded! Welcome!', 'success'); - // Create a demo user object - this.user = { - email: 'google-user@gmail.com', - full_name: 'Google User', - is_premium: true - }; - this.isPremium = true; - this.showScreen('homeScreen'); - this.loadWeatherData(); - } - }, 1500); // Simulate OAuth redirect delay + await new Promise(resolve => setTimeout(resolve, 1500)); + try { + // Auto-login with demo account + const response = await api.login('demo@climaai.com', 'Test1234'); + this.user = response.user; + this.showToast('✅ Welcome! Signed in with Google', 'success'); + this.showScreen('homeScreen'); + this.loadWeatherData(); + this.checkSubscription(); + } catch (error) { + this.showToast('Google Sign-In succeeded! Welcome!', 'success'); + // Create a demo user object + this.user = { + email: 'google-user@gmail.com', + full_name: 'Google User', + is_premium: true + }; + this.isPremium = true; + this.showScreen('homeScreen'); + this.loadWeatherData(); + } } catch (error) { this.showToast(error.message || 'Google Sign-In failed', 'error'); + } finally { + if (btn) { + btn.innerHTML = originalContent; + btn.disabled = false; + btn.removeAttribute('aria-busy'); + } } }