Mobile-first PWA: groups via key-in-fragment links, encrypted outbox and sync over SSE, all split modes, currencies with ECB rate prefill, photos, comments, history and rewind, stats, recurring expenses, CSV and backup, EN/CS, dark/light theme, Web Push decrypted in the service worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
95 lines
3.6 KiB
Svelte
95 lines
3.6 KiB
Svelte
<script lang="ts">
|
|
import { getAll, type LocalGroup } from '../lib/idb.ts';
|
|
import { isGroupId, isGroupSecret } from '../lib/crypto.ts';
|
|
import { money } from '../lib/format.ts';
|
|
import { router } from '../lib/router.svelte.ts';
|
|
import { addGroup } from '../lib/session.svelte.ts';
|
|
import { t } from '../lib/settings.svelte.ts';
|
|
import Icon from './Icon.svelte';
|
|
|
|
let groups = $state<LocalGroup[] | null>(null);
|
|
let link = $state('');
|
|
let linkError = $state(false);
|
|
let showLink = $state(false);
|
|
|
|
getAll<LocalGroup>('groups').then((g) => (groups = g.sort((a, b) => b.lastOpened - a.lastOpened)));
|
|
|
|
async function openLink(e: SubmitEvent) {
|
|
e.preventDefault();
|
|
const m = /\/g\/([A-Za-z0-9_-]{22})#([A-Za-z0-9_-]{43})\s*$/.exec(link.trim());
|
|
if (!m || !isGroupId(m[1]) || !isGroupSecret(m[2])) {
|
|
linkError = true;
|
|
return;
|
|
}
|
|
await addGroup(m[1], m[2]);
|
|
router.go(`/g/${m[1]}`);
|
|
}
|
|
|
|
function nav(e: MouseEvent, path: string) {
|
|
e.preventDefault();
|
|
router.go(path);
|
|
}
|
|
</script>
|
|
|
|
<header class="topbar">
|
|
<h1><span aria-hidden="true">💸</span> {t('app_name')}</h1>
|
|
<a class="icon-btn" href="/settings" onclick={(e) => nav(e, '/settings')} aria-label={t('settings')}><Icon name="settings" /></a>
|
|
</header>
|
|
|
|
<main class="page stack">
|
|
<p class="muted">{t('tagline')}</p>
|
|
|
|
<div class="section">
|
|
<h3>{t('your_groups')}</h3>
|
|
{#if groups === null}
|
|
<p class="muted">{t('loading')}</p>
|
|
{:else if groups.length === 0}
|
|
<p class="card muted">{t('no_groups')}</p>
|
|
{:else}
|
|
<div class="list">
|
|
{#each groups as g (g.id)}
|
|
<a class="item" href="/g/{g.id}" onclick={(e) => nav(e, `/g/${g.id}`)}>
|
|
<span class="cat-icon" aria-hidden="true">{g.icon || '👥'}</span>
|
|
<span class="grow">
|
|
<span class="title" style:display="block">{g.name || '…'}</span>
|
|
<span class="sub" style:display="block">
|
|
{#if g.gone}
|
|
{t('group_gone')}
|
|
{:else if g.myBalance === null}
|
|
{t('pick_identity_hint')}
|
|
{:else if g.myBalance > 0}
|
|
<span class="pos">{t('you_are_owed', { amount: money(g.myBalance, g.baseCurrency) })}</span>
|
|
{:else if g.myBalance < 0}
|
|
<span class="neg">{t('you_owe', { amount: money(-g.myBalance, g.baseCurrency) })}</span>
|
|
{:else}
|
|
{t('settled')}
|
|
{/if}
|
|
</span>
|
|
</span>
|
|
</a>
|
|
{/each}
|
|
</div>
|
|
{/if}
|
|
</div>
|
|
|
|
<div class="section">
|
|
<a class="btn primary block" href="/new" onclick={(e) => nav(e, '/new')}><Icon name="plus" /> {t('new_group')}</a>
|
|
{#if showLink}
|
|
<form class="stack card" onsubmit={openLink}>
|
|
<label class="field">
|
|
{t('paste_link')}
|
|
<input bind:value={link} oninput={() => (linkError = false)} placeholder="https://…/g/…#…" autocomplete="off" spellcheck="false" />
|
|
</label>
|
|
{#if linkError}<p class="neg small" role="alert">{t('invalid_link')}</p>{/if}
|
|
<button class="btn" type="submit">{t('open')}</button>
|
|
</form>
|
|
{:else}
|
|
<button class="btn block" onclick={() => (showLink = true)}><Icon name="link" /> {t('open_link')}</button>
|
|
{/if}
|
|
<a class="btn ghost block" href="/restore" onclick={(e) => nav(e, '/restore')}><Icon name="upload" /> {t('restore_backup')}</a>
|
|
</div>
|
|
|
|
<p class="muted small row" style:align-items="flex-start" style:margin-top="24px">
|
|
<Icon name="lock" size={16} /> <span>{t('e2e_note')}</span>
|
|
</p>
|
|
</main>
|