From 29af920dfbf70b6760ada413c6ae3abbd0ed78fa Mon Sep 17 00:00:00 2001 From: Mateusz Pstrucha Date: Sun, 4 Oct 2026 14:11:10 +0200 Subject: [PATCH] Edit accounts from the Accounts screen Each account gets an Edit button opening the add form pre-filled with its settings; the password field is optional ("unchanged") and only a new value replaces the stored one. Editing no longer rewrites the hosts or login from the address, so a working setup isn't silently changed. Co-Authored-By: Claude Opus 5.5 --- src/lib/AccountsView.svelte | 98 ++++++++++++++++++++++++++++--------- src/lib/api.ts | 8 +++ 2 files changed, 82 insertions(+), 24 deletions(-) diff --git a/src/lib/AccountsView.svelte b/src/lib/AccountsView.svelte index 1ad6810..1b12a89 100644 --- a/src/lib/AccountsView.svelte +++ b/src/lib/AccountsView.svelte @@ -3,7 +3,7 @@ // the form to connect another. Only the server ever talks to the mail // server (server-architecture-spec.md §2); this screen just hands it the // settings and shows what it reports back. - import { createAccount, deleteAccount, listAccounts, type Account } from './api'; + import { createAccount, deleteAccount, listAccounts, updateAccount, type Account } from './api'; import { formatFullDate } from './format'; let { @@ -23,6 +23,8 @@ let loaded = $state(false); let error = $state(null); let adding = $state(false); + /** The account being edited; the form is shared with adding. */ + let editing = $state(null); let saving = $state(false); let formError = $state(null); @@ -81,28 +83,51 @@ formError = null; } - async function add(event: SubmitEvent) { + function startEdit(a: Account) { + adding = false; + editing = a; + email = a.email_address ?? ''; + displayName = a.display_name ?? ''; + imapHost = a.imap_host; + imapPort = a.imap_port; + smtpHost = a.smtp_host; + smtpPort = a.smtp_port; + login = a.username; + password = ''; + // Editing the address must not silently rewrite settings that work. + loginEdited = hostsEdited = true; + formError = null; + } + + function closeForm() { + adding = false; + editing = null; + resetForm(); + } + + async function save(event: SubmitEvent) { event.preventDefault(); saving = true; formError = null; + const settings = { + name: editing?.name ?? (email.split('@')[1] || email), + imap_host: imapHost.trim(), + imap_port: Number(imapPort), + smtp_host: smtpHost.trim(), + smtp_port: Number(smtpPort), + username: login.trim(), + password, + email_address: email.trim() || null, + display_name: displayName.trim() || null, + }; try { - await createAccount({ - name: email.split('@')[1] || email, - imap_host: imapHost.trim(), - imap_port: Number(imapPort), - smtp_host: smtpHost.trim(), - smtp_port: Number(smtpPort), - username: login.trim(), - password, - email_address: email.trim() || null, - display_name: displayName.trim() || null, - }); - resetForm(); - adding = false; + if (editing) await updateAccount(editing.id, settings); + else await createAccount(settings); + closeForm(); await load(); onChanged?.(); } catch (e) { - formError = e instanceof Error ? e.message : 'failed to add the account'; + formError = e instanceof Error ? e.message : 'failed to save the account'; } finally { saving = false; } @@ -144,7 +169,7 @@

Accounts

- {#if !adding} + {#if !adding && !editing} {/if}
@@ -170,15 +195,22 @@ {/if} {#if a.sync}Last update {formatFullDate(a.sync.updated_at)}{/if}
- +
+ + +
{/each} {/if} - {#if adding} -
-

{accounts.length === 0 ? 'Connect your first mailbox' : 'Add an account'}

+ {#if adding || editing} + +

+ {#if editing}Edit {editing.email_address ?? editing.username} + {:else if accounts.length === 0}Connect your first mailbox + {:else}Add an account{/if} +

@@ -201,8 +233,20 @@ (loginEdited = true)} required autocomplete="username" /> + {#if editing} +

+ Saving reconnects with the new settings. Mail already here stays as long as it's the same mailbox; + point it at a different one and it's synced afresh. +

+ {/if}

Stored encrypted on your Tern server, never in this browser. Tern only reads your inbox and sends — it never changes anything on the mail server. @@ -210,9 +254,11 @@ {#if formError}

{formError}

{/if}
{#if accounts.length > 0} - + {/if} - +
{/if} @@ -264,6 +310,10 @@ border: 1px solid var(--secondary); border-radius: 0.45rem; } + .row-actions { + display: flex; + gap: 0.4rem; + } .body { flex: 1; min-width: 0; diff --git a/src/lib/api.ts b/src/lib/api.ts index 7223fdd..f3fe4bf 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -236,6 +236,14 @@ export function createAccount(account: NewAccount): Promise { return request('/accounts', { method: 'POST', body: JSON.stringify(account) }); } +/** + * Replaces an account's settings. Leave `password` empty to keep the + * stored one. The server restarts the account's sync with the new settings. + */ +export function updateAccount(id: string, account: NewAccount): Promise { + return request(`/accounts/${id}`, { method: 'PUT', body: JSON.stringify(account) }); +} + /** Removes the account and every message synced from it. */ export function deleteAccount(id: string): Promise<{ ok: boolean }> { return request(`/accounts/${id}`, { method: 'DELETE' });