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 <noreply@anthropic.com>
This commit is contained in:
1 parent
f763777477
commit
29af920dfb
2 files changed
+82
-24
No files matched your search
+74
-24
@@ -3,7 +3,7 @@
|
|||||||
// the form to connect another. Only the server ever talks to the mail
|
// 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
|
// server (server-architecture-spec.md §2); this screen just hands it the
|
||||||
// settings and shows what it reports back.
|
// 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';
|
import { formatFullDate } from './format';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
let loaded = $state(false);
|
let loaded = $state(false);
|
||||||
let error = $state<string | null>(null);
|
let error = $state<string | null>(null);
|
||||||
let adding = $state(false);
|
let adding = $state(false);
|
||||||
|
/** The account being edited; the form is shared with adding. */
|
||||||
|
let editing = $state<Account | null>(null);
|
||||||
let saving = $state(false);
|
let saving = $state(false);
|
||||||
let formError = $state<string | null>(null);
|
let formError = $state<string | null>(null);
|
||||||
|
|
||||||
@@ -81,28 +83,51 @@
|
|||||||
formError = null;
|
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();
|
event.preventDefault();
|
||||||
saving = true;
|
saving = true;
|
||||||
formError = null;
|
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 {
|
try {
|
||||||
await createAccount({
|
if (editing) await updateAccount(editing.id, settings);
|
||||||
name: email.split('@')[1] || email,
|
else await createAccount(settings);
|
||||||
imap_host: imapHost.trim(),
|
closeForm();
|
||||||
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;
|
|
||||||
await load();
|
await load();
|
||||||
onChanged?.();
|
onChanged?.();
|
||||||
} catch (e) {
|
} 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 {
|
} finally {
|
||||||
saving = false;
|
saving = false;
|
||||||
}
|
}
|
||||||
@@ -144,7 +169,7 @@
|
|||||||
<div class="accounts">
|
<div class="accounts">
|
||||||
<header>
|
<header>
|
||||||
<h2>Accounts</h2>
|
<h2>Accounts</h2>
|
||||||
{#if !adding}
|
{#if !adding && !editing}
|
||||||
<button class="primary" onclick={() => { resetForm(); adding = true; }}>Add account</button>
|
<button class="primary" onclick={() => { resetForm(); adding = true; }}>Add account</button>
|
||||||
{/if}
|
{/if}
|
||||||
</header>
|
</header>
|
||||||
@@ -170,15 +195,22 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{#if a.sync}<span class="detail">Last update {formatFullDate(a.sync.updated_at)}</span>{/if}
|
{#if a.sync}<span class="detail">Last update {formatFullDate(a.sync.updated_at)}</span>{/if}
|
||||||
</div>
|
</div>
|
||||||
<button onclick={() => remove(a)}>Remove</button>
|
<div class="row-actions">
|
||||||
|
<button onclick={() => startEdit(a)} disabled={editing?.id === a.id}>Edit</button>
|
||||||
|
<button onclick={() => remove(a)}>Remove</button>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if adding}
|
{#if adding || editing}
|
||||||
<form onsubmit={add}>
|
<form onsubmit={save}>
|
||||||
<h3>{accounts.length === 0 ? 'Connect your first mailbox' : 'Add an account'}</h3>
|
<h3>
|
||||||
|
{#if editing}Edit {editing.email_address ?? editing.username}
|
||||||
|
{:else if accounts.length === 0}Connect your first mailbox
|
||||||
|
{:else}Add an account{/if}
|
||||||
|
</h3>
|
||||||
<label class="wide">Email address
|
<label class="wide">Email address
|
||||||
<input type="email" bind:value={email} oninput={emailChanged} required autocomplete="email" />
|
<input type="email" bind:value={email} oninput={emailChanged} required autocomplete="email" />
|
||||||
</label>
|
</label>
|
||||||
@@ -201,8 +233,20 @@
|
|||||||
<input bind:value={login} oninput={() => (loginEdited = true)} required autocomplete="username" />
|
<input bind:value={login} oninput={() => (loginEdited = true)} required autocomplete="username" />
|
||||||
</label>
|
</label>
|
||||||
<label class="wide">Password
|
<label class="wide">Password
|
||||||
<input type="password" bind:value={password} required autocomplete="current-password" />
|
<input
|
||||||
|
type="password"
|
||||||
|
bind:value={password}
|
||||||
|
required={!editing}
|
||||||
|
placeholder={editing ? 'unchanged — type a new one to replace it' : ''}
|
||||||
|
autocomplete={editing ? 'new-password' : 'current-password'}
|
||||||
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
{#if editing}
|
||||||
|
<p class="hint wide">
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
{/if}
|
||||||
<p class="hint wide">
|
<p class="hint wide">
|
||||||
Stored encrypted on your Tern server, never in this browser. Tern only reads your inbox and sends —
|
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.
|
it never changes anything on the mail server.
|
||||||
@@ -210,9 +254,11 @@
|
|||||||
{#if formError}<p class="error wide">{formError}</p>{/if}
|
{#if formError}<p class="error wide">{formError}</p>{/if}
|
||||||
<div class="actions wide">
|
<div class="actions wide">
|
||||||
{#if accounts.length > 0}
|
{#if accounts.length > 0}
|
||||||
<button type="button" onclick={() => { adding = false; resetForm(); }}>Cancel</button>
|
<button type="button" onclick={closeForm}>Cancel</button>
|
||||||
{/if}
|
{/if}
|
||||||
<button type="submit" class="primary" disabled={saving}>{saving ? 'Adding…' : 'Add account'}</button>
|
<button type="submit" class="primary" disabled={saving}>
|
||||||
|
{saving ? 'Saving…' : editing ? 'Save changes' : 'Add account'}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -264,6 +310,10 @@
|
|||||||
border: 1px solid var(--secondary);
|
border: 1px solid var(--secondary);
|
||||||
border-radius: 0.45rem;
|
border-radius: 0.45rem;
|
||||||
}
|
}
|
||||||
|
.row-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 0.4rem;
|
||||||
|
}
|
||||||
.body {
|
.body {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
|
|||||||
@@ -236,6 +236,14 @@ export function createAccount(account: NewAccount): Promise<Account> {
|
|||||||
return request('/accounts', { method: 'POST', body: JSON.stringify(account) });
|
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<Account> {
|
||||||
|
return request(`/accounts/${id}`, { method: 'PUT', body: JSON.stringify(account) });
|
||||||
|
}
|
||||||
|
|
||||||
/** Removes the account and every message synced from it. */
|
/** Removes the account and every message synced from it. */
|
||||||
export function deleteAccount(id: string): Promise<{ ok: boolean }> {
|
export function deleteAccount(id: string): Promise<{ ok: boolean }> {
|
||||||
return request(`/accounts/${id}`, { method: 'DELETE' });
|
return request(`/accounts/${id}`, { method: 'DELETE' });
|
||||||
|
|||||||
Reference in new issue
Block a user