Layout, from the approved mock: - Group header on Expenses/Balances: my balance as the headline number (Money component de-emphasises currency and decimals), total spent, and round quick actions Add / Payment / Settle up / Share. The floating + shows only once those scroll off screen. - Expense rows on two lines (title | amount, payer | my part) with round icons tinted per category; sentence-case section headings. - Balances: larger avatars, paired avatars on settle-up rows, tinted button. Bugs found in a screenshot pass (phone 320/390, desktop 1280; dark, black, light; English and Czech): - A long title or member name widened the group page past the screen and phones zoomed out (grid tracks without minmax(0, ...)); same in Stats. - Long titles were clipped mid-word with no ellipsis. - Category emoji nearly invisible on its grey circle in the light theme. - Stats period labels wrapped (en) or ran off screen (cs); shortened. - Icons next to wrapping text were squashed (lock on Home/App settings). - Dialogs opened with a focus ring on the close button after a tap. - New expenses always defaulted to Food & drink; now the group's default category (settable in group settings), else Other. e2e: the Balances check now targets the Settle up heading, which the new quick action shares its text with. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
101 lines
4.3 KiB
Svelte
101 lines
4.3 KiB
Svelte
<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={40} />
|
||
<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'}" style:font-weight="650">
|
||
{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}
|
||
{@const from = session.state.members.findIndex((m) => m.id === tr.from)}
|
||
{@const to = session.state.members.findIndex((m) => m.id === tr.to)}
|
||
<div class="item">
|
||
<span class="pair" aria-hidden="true">
|
||
<Avatar member={session.state.members[from]} index={from} size={34} />
|
||
<Avatar member={session.state.members[to]} index={to} size={34} />
|
||
</span>
|
||
<span class="grow">
|
||
<span class="title" style:display="block">{session.memberName(tr.from)} → {session.memberName(tr.to)}</span>
|
||
<span class="num sub" style:display="block">{conv(tr.amount)}</span>
|
||
</span>
|
||
<button class="btn small tint" 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>
|
||
.pair { display: flex; flex-shrink: 0; }
|
||
.pair :global(.avatar) { box-shadow: 0 0 0 3px var(--surface); }
|
||
.pair :global(.avatar + .avatar) { margin-left: -10px; }
|
||
.bar { display: block; height: 5px; margin-top: 7px; 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>
|