Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Jules/palette.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2024-05-14 - Missing Loading States on Async Actions
**Learning:** In the ClimaAI app, form buttons (Login, Register, Google Auth) lack visual feedback and disable states during async API requests.
**Action:** Always add loading spinners/text changes and disable the button natively (via `disabled=true` and `aria-busy=true`) during async submissions to prevent double-clicks and provide immediate feedback. Use `try...finally` to ensure state is cleaned up robustly.
15 changes: 15 additions & 0 deletions web-demo/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.disabled = true;
submitBtn.setAttribute('aria-busy', 'true');
submitBtn.innerHTML = 'Signing in...';
}

try {
this.showToast('Logging in...', 'info');
Expand All @@ -155,6 +164,12 @@ class ClimaAI {
this.checkSubscription();
} catch (error) {
this.showToast(error.message || 'Login failed', 'error');
} finally {
if (submitBtn) {
submitBtn.disabled = false;
submitBtn.removeAttribute('aria-busy');
submitBtn.innerHTML = originalContent;
}
}
}

Expand Down