Rewrites the web app's comments to rule 32. Task, milestone, rule and spec ids are gone; regression stories are restated as the trap they guard (public auth routes, the menu's stopPropagation, universal loads under adapter-static, metric deltas with their margin). Flutter and Tauri mentions now name the Android app or a native shell, operator quotes and dates are dropped, and one library's counts no longer appear outside test fixtures. Verified with a TypeScript-scanner token comparison (template literals and regex literals re-scanned): only comment text changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
198 lines
7.0 KiB
Svelte
198 lines
7.0 KiB
Svelte
<script lang="ts">
|
||
import SettingsColumns from '#lib/components/settings/SettingsColumns.svelte';
|
||
import { onMount } from 'svelte';
|
||
import { useQueryClient } from '@tanstack/svelte-query';
|
||
import { pageTitle } from '#lib/branding.js';
|
||
import { getMyProfile, updateProfile, changePassword, type MyProfile } from '#lib/api/me.js';
|
||
import { errCode } from '#lib/api/errors.js';
|
||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||
import MobileAppDownload from '#lib/components/MobileAppDownload.svelte';
|
||
import ActiveSessions from '#lib/components/ActiveSessions.svelte';
|
||
import SettingsGroup from '#lib/components/settings/SettingsGroup.svelte';
|
||
import SettingRow from '#lib/components/settings/SettingRow.svelte';
|
||
|
||
// Settings › Account, where /settings lands: the Android app,
|
||
// the profile, the password and the devices signed in.
|
||
|
||
const queryClient = useQueryClient();
|
||
const input =
|
||
'w-64 max-w-full rounded-md border border-border bg-background px-3 py-1.5 text-sm outline-hidden focus:border-accent disabled:opacity-60';
|
||
const primary =
|
||
'rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg hover:opacity-90 disabled:opacity-50';
|
||
|
||
// Profile -------------------------------------------------------------------
|
||
// The form is filled from what is stored before it can be saved, and a
|
||
// save sends only what changed: a blank field clears that field on the
|
||
// server.
|
||
|
||
let stored = $state<MyProfile | null>(null);
|
||
let loadFailed = $state(false);
|
||
let displayName = $state('');
|
||
let email = $state('');
|
||
let profileSaving = $state(false);
|
||
|
||
async function loadProfile() {
|
||
loadFailed = false;
|
||
try {
|
||
stored = await getMyProfile();
|
||
displayName = stored.display_name ?? '';
|
||
email = stored.email ?? '';
|
||
} catch {
|
||
loadFailed = true;
|
||
}
|
||
}
|
||
onMount(loadProfile);
|
||
|
||
const changes = $derived.by(() => {
|
||
if (!stored) return {};
|
||
const c: { display_name?: string; email?: string } = {};
|
||
if (displayName.trim() !== (stored.display_name ?? '')) c.display_name = displayName;
|
||
if (email.trim().toLowerCase() !== (stored.email ?? '')) c.email = email;
|
||
return c;
|
||
});
|
||
const dirty = $derived(Object.keys(changes).length > 0);
|
||
|
||
async function onSaveProfile(e: SubmitEvent) {
|
||
e.preventDefault();
|
||
if (!dirty) return;
|
||
profileSaving = true;
|
||
try {
|
||
stored = await updateProfile(changes);
|
||
displayName = stored.display_name ?? '';
|
||
email = stored.email ?? '';
|
||
pushToast('Profile saved.');
|
||
// Whether email notifications are possible depends on the address.
|
||
queryClient.invalidateQueries({ queryKey: ['notificationSettings'] });
|
||
} catch (err: unknown) {
|
||
const code = errCode(err);
|
||
if (code === 'email_taken') pushToast('That email is already in use.', 'error');
|
||
else if (code === 'email_invalid') pushToast('Email format is invalid.', 'error');
|
||
else pushToast(`Save failed: ${code}`, 'error');
|
||
} finally {
|
||
profileSaving = false;
|
||
}
|
||
}
|
||
|
||
// Password ------------------------------------------------------------------
|
||
|
||
let current = $state('');
|
||
let next = $state('');
|
||
let confirm = $state('');
|
||
let passwordSaving = $state(false);
|
||
|
||
async function onSavePassword(e: SubmitEvent) {
|
||
e.preventDefault();
|
||
if (next !== confirm) {
|
||
pushToast('New passwords do not match.', 'error');
|
||
return;
|
||
}
|
||
passwordSaving = true;
|
||
try {
|
||
await changePassword(current, next);
|
||
pushToast('Password changed. Your other devices have been signed out.');
|
||
current = next = confirm = '';
|
||
} catch (err: unknown) {
|
||
const code = errCode(err);
|
||
if (code === 'wrong_password') pushToast('Current password is incorrect.', 'error');
|
||
else if (code === 'password_too_short') pushToast('Password must be at least 8 characters.', 'error');
|
||
else pushToast(`Change failed: ${code}`, 'error');
|
||
} finally {
|
||
passwordSaving = false;
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<svelte:head><title>{pageTitle('Settings · Account')}</title></svelte:head>
|
||
|
||
<SettingsColumns>
|
||
{#snippet main()}
|
||
<MobileAppDownload />
|
||
|
||
<form onsubmit={onSaveProfile}>
|
||
<SettingsGroup title="Profile" id="profile">
|
||
{#if loadFailed}
|
||
<div class="px-4 py-3 text-sm text-text-secondary">
|
||
Couldn't load your profile.
|
||
<button type="button" class="underline hover:text-text-primary" onclick={loadProfile}>Try again</button>
|
||
</div>
|
||
{:else}
|
||
<SettingRow label="Username">
|
||
<span class="text-sm text-text-secondary">{stored?.username ?? '…'}</span>
|
||
</SettingRow>
|
||
<SettingRow label="Display name" hint="Shown in place of your username." for="profile-displayname">
|
||
<input
|
||
id="profile-displayname"
|
||
type="text"
|
||
maxlength="64"
|
||
disabled={!stored}
|
||
bind:value={displayName}
|
||
class={input}
|
||
/>
|
||
</SettingRow>
|
||
<SettingRow label="Email" hint="For password resets and email notifications." for="profile-email">
|
||
<input
|
||
id="profile-email"
|
||
type="email"
|
||
autocomplete="email"
|
||
disabled={!stored}
|
||
bind:value={email}
|
||
class={input}
|
||
/>
|
||
</SettingRow>
|
||
<div class="flex justify-end px-4 py-3">
|
||
<button type="submit" disabled={!dirty || profileSaving} class={primary}>
|
||
{profileSaving ? 'Saving…' : 'Save profile'}
|
||
</button>
|
||
</div>
|
||
{/if}
|
||
</SettingsGroup>
|
||
</form>
|
||
|
||
<form onsubmit={onSavePassword}>
|
||
<SettingsGroup title="Password" hint="Changing it signs out your other devices.">
|
||
<SettingRow label="Current password" for="password-current">
|
||
<input
|
||
id="password-current"
|
||
type="password"
|
||
required
|
||
minlength="8"
|
||
autocomplete="current-password"
|
||
bind:value={current}
|
||
class={input}
|
||
/>
|
||
</SettingRow>
|
||
<SettingRow label="New password" hint="At least 8 characters." for="password-new">
|
||
<input
|
||
id="password-new"
|
||
type="password"
|
||
required
|
||
minlength="8"
|
||
autocomplete="new-password"
|
||
bind:value={next}
|
||
class={input}
|
||
/>
|
||
</SettingRow>
|
||
<SettingRow label="Confirm new password" for="password-confirm">
|
||
<input
|
||
id="password-confirm"
|
||
type="password"
|
||
required
|
||
minlength="8"
|
||
autocomplete="new-password"
|
||
bind:value={confirm}
|
||
class={input}
|
||
/>
|
||
</SettingRow>
|
||
<div class="flex justify-end px-4 py-3">
|
||
<button type="submit" disabled={passwordSaving || !current || !next || !confirm} class={primary}>
|
||
{passwordSaving ? 'Saving…' : 'Change password'}
|
||
</button>
|
||
</div>
|
||
</SettingsGroup>
|
||
</form>
|
||
{/snippet}
|
||
{#snippet side()}
|
||
<ActiveSessions />
|
||
{/snippet}
|
||
</SettingsColumns>
|