Add Svelte web client and service worker
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
This commit is contained in:
parent
f67add3660
commit
8fbbb4933e
53 changed files with 4558 additions and 37 deletions
92
apps/web/src/components/Balances.svelte
Normal file
92
apps/web/src/components/Balances.svelte
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { exponent, settleUp } from '@oweme/core';
|
||||
import { money } from '../lib/format.ts';
|
||||
import { displayRate } from '../lib/rates.ts';
|
||||
import { router } from '../lib/router.svelte.ts';
|
||||
import type { GroupSession } from '../lib/session.svelte.ts';
|
||||
import { t } from '../lib/settings.svelte.ts';
|
||||
import Avatar from './Avatar.svelte';
|
||||
import CurrencySelect from './CurrencySelect.svelte';
|
||||
|
||||
let { session, compact = false }: { session: GroupSession; compact?: boolean } = $props();
|
||||
|
||||
// Optional display in another currency at today's rate (never stored).
|
||||
let showIn = $state(untrack(() => session.base));
|
||||
let factor = $state<number | null>(1);
|
||||
$effect(() => {
|
||||
const target = showIn || session.base;
|
||||
displayRate(session.base, target).then((r) => (factor = r));
|
||||
});
|
||||
const cur = $derived(factor === null ? session.base : showIn || session.base);
|
||||
const conv = (v: number) => {
|
||||
if (!showIn || showIn === session.base || factor === null) return money(v, session.base);
|
||||
// display only: float maths is fine here
|
||||
return money(Math.round(v * factor * 10 ** (exponent(cur) - exponent(session.base))), cur);
|
||||
};
|
||||
|
||||
const members = $derived(session.state.members.map((m, i) => ({ m, i, bal: session.balances[m.id] ?? 0 })).filter((x) => !x.m.archived || x.bal !== 0));
|
||||
const maxAbs = $derived(Math.max(1, ...members.map((x) => Math.abs(x.bal))));
|
||||
const transfers = $derived(settleUp(session.balances, session.state.members.map((m) => m.id)));
|
||||
|
||||
function record(from: string, to: string, amount: number) {
|
||||
const p = new URLSearchParams({ kind: 'transfer', from, to, amount: String(amount) });
|
||||
router.go(`/g/${session.id}/e/new?${p}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="stack">
|
||||
{#if !compact}
|
||||
<h3>{t('balances')}</h3>
|
||||
{/if}
|
||||
<div class="list">
|
||||
{#each members as { m, i, bal } (m.id)}
|
||||
<div class="item">
|
||||
<Avatar member={m} index={i} size={32} />
|
||||
<span class="grow">
|
||||
<span class="title" style:display="block">{m.name}{m.id === session.me ? ` (${t('you')})` : ''}</span>
|
||||
<span class="bar" aria-hidden="true">
|
||||
<span class={bal >= 0 ? 'fill pos-fill' : 'fill neg-fill'} style:width="{(Math.abs(bal) / maxAbs) * 100}%"></span>
|
||||
</span>
|
||||
</span>
|
||||
<span class="end num {bal > 0 ? 'pos' : bal < 0 ? 'neg' : 'muted'}">
|
||||
{bal === 0 ? t('settled') : (bal > 0 ? '+' : '−') + conv(Math.abs(bal))}
|
||||
</span>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<h3 style:margin-top="12px">{t('settle_up')}</h3>
|
||||
{#if transfers.length === 0}
|
||||
<p class="card muted">{t('all_settled')}</p>
|
||||
{:else}
|
||||
<div class="list">
|
||||
{#each transfers as tr}
|
||||
<div class="item">
|
||||
<span class="grow">
|
||||
<span class="title" style:display="block">{session.memberName(tr.from)} → {session.memberName(tr.to)}</span>
|
||||
<span class="num" style:font-weight="700">{conv(tr.amount)}</span>
|
||||
</span>
|
||||
<button class="btn small" onclick={() => record(tr.from, tr.to, tr.amount)}>{t('mark_paid')}</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if !compact}
|
||||
<label class="field" style:margin-top="12px">
|
||||
{t('show_in')}
|
||||
<CurrencySelect bind:value={showIn} />
|
||||
{#if showIn && showIn !== session.base}
|
||||
<span class="small">{factor === null ? t('rate_unavailable') : t('display_only_rate')}</span>
|
||||
{/if}
|
||||
</label>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.bar { display: block; height: 6px; margin-top: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
|
||||
.fill { display: block; height: 100%; border-radius: 3px; }
|
||||
.pos-fill { background: var(--accent); }
|
||||
.neg-fill { background: var(--owe); }
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue