mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 17:55:26 -04:00
Email accounts strip: rename 'All (default)' → 'Default', add star toggle
- 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.
This commit is contained in:
@@ -1330,11 +1330,20 @@ function _renderAccountsStrip() {
|
||||
strip.style.display = 'flex';
|
||||
const esc = s => String(s || '').replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"');
|
||||
const allActive = !state._libAccountId ? ' active' : '';
|
||||
let html = `<button class="memory-toolbar-btn gallery-chip${allActive}" data-acc-id="">All (default)</button>`;
|
||||
// 'Default' rather than 'All (default)' — this view shows the account
|
||||
// marked is_default; cross-account aggregation is a separate feature.
|
||||
let html = `<button class="memory-toolbar-btn gallery-chip${allActive}" data-acc-id="">Default</button>`;
|
||||
const _starFilled = '<svg width="11" height="11" viewBox="0 0 24 24" fill="currentColor" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>';
|
||||
const _starHollow = '<svg width="11" height="11" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/></svg>';
|
||||
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 += `<button class="memory-toolbar-btn gallery-chip${active}" data-acc-id="${esc(a.id)}" title="${esc(a.from_address || a.imap_user || '')}${a.is_default ? ' (default)' : ''}">${esc(label)}</button>`;
|
||||
const star = a.is_default ? _starFilled : _starHollow;
|
||||
const starTitle = a.is_default ? 'Default account' : 'Set as default';
|
||||
html += `<span class="gallery-chip-wrap" style="position:relative;display:inline-flex;align-items:center;">`
|
||||
+ `<button class="memory-toolbar-btn gallery-chip${active}" data-acc-id="${esc(a.id)}" title="${esc(a.from_address || a.imap_user || '')}${a.is_default ? ' (default)' : ''}" style="padding-right:22px;">${esc(label)}</button>`
|
||||
+ `<button class="email-lib-default-star${a.is_default ? ' is-default' : ''}" data-set-default="${esc(a.id)}" title="${starTitle}" aria-label="${starTitle}" style="position:absolute;right:4px;top:50%;transform:translateY(-50%);background:none;border:0;padding:2px;cursor:pointer;color:${a.is_default ? 'var(--accent, var(--red))' : 'inherit'};opacity:${a.is_default ? '1' : '0.45'};display:inline-flex;align-items:center;">${star}</button>`
|
||||
+ `</span>`;
|
||||
}
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user