From c637b5057b38d354a6c952b578e66ef0bfb26ee6 Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Thu, 11 Jun 2026 09:12:37 +0900 Subject: [PATCH] =?UTF-8?q?Email=20accounts=20strip:=20rename=20'All=20(de?= =?UTF-8?q?fault)'=20=E2=86=92=20'Default',=20add=20star=20toggle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The 'All (default)' chip showed only the default account, so the label was misleading. Rename to just 'Default' to match behavior. - Each user account chip gets a star button (filled if it IS the default, hollow otherwise). Clicking calls the existing POST /api/email/accounts/{id}/set-default and refreshes the strip. Cross-account aggregation (a true 'All') is a separate bigger lift that needs UID namespacing and merge/sort in _list_emails_sync; flagged for follow-up rather than smuggled into this change. --- static/js/emailLibrary.js | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/static/js/emailLibrary.js b/static/js/emailLibrary.js index b7d4504da..b1883eb21 100644 --- a/static/js/emailLibrary.js +++ b/static/js/emailLibrary.js @@ -1330,11 +1330,20 @@ function _renderAccountsStrip() { strip.style.display = 'flex'; const esc = s => String(s || '').replace(/&/g, '&').replace(/All (default)`; + // 'Default' rather than 'All (default)' — this view shows the account + // marked is_default; cross-account aggregation is a separate feature. + let html = ``; + const _starFilled = ''; + const _starHollow = ''; for (const a of state._libAccounts) { const active = state._libAccountId === a.id ? ' active' : ''; const label = a.name || a.from_address || a.imap_user || 'account'; - html += ``; + const star = a.is_default ? _starFilled : _starHollow; + const starTitle = a.is_default ? 'Default account' : 'Set as default'; + html += `` + + `` + + `` + + ``; } strip.innerHTML = html; strip.querySelectorAll('button[data-acc-id]').forEach(btn => { @@ -1347,6 +1356,25 @@ function _renderAccountsStrip() { _loadEmails({ force: true, useCache: false }); }); }); + // Star handler: POST set-default, then reload accounts + re-render so + // the chip stars reflect the new default. + strip.querySelectorAll('button[data-set-default]').forEach(btn => { + btn.addEventListener('click', async (e) => { + e.stopPropagation(); + const acctId = btn.dataset.setDefault; + if (!acctId) return; + try { + await fetch(`${API_BASE}/api/email/accounts/${encodeURIComponent(acctId)}/set-default`, { + method: 'POST', credentials: 'same-origin', + }); + // Refresh the local accounts cache and re-render the strip. + for (const a of state._libAccounts) a.is_default = (a.id === acctId); + _renderAccountsStrip(); + } catch (err) { + console.error('Set default account failed:', err); + } + }); + }); // Idempotent — wire wheel + grab-drag scroll once per strip element. if (!strip._scrollWired) { strip._scrollWired = true;