Compare commits
11 commits
feat/theme
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e6b06b399 | |||
| 9981cf9a9a | |||
| 61f4e42846 | |||
| 3d2f87c967 | |||
| ce1b207906 | |||
| a10ec3c3b3 | |||
| 5f40882cd5 | |||
| 271d3e8a66 | |||
| 88024b4702 | |||
| b3b57c156e | |||
| c12fd64f09 |
21 changed files with 949 additions and 241 deletions
46
SPEC.md
46
SPEC.md
|
|
@ -180,8 +180,11 @@ Split `value` meaning per mode:
|
|||
| `exact` | amount in minor units | sum == amount |
|
||||
| `percent` | basis points (100 % = 10000) | sum == 10000 |
|
||||
|
||||
Multiple payers are supported (`payers` list); the default UI shows a single
|
||||
payer with an "add payer" option.
|
||||
Multiple payers are supported (`payers` list) — e.g. several people chipping
|
||||
in for a car. The editor shows a single payer by default; choosing "Several
|
||||
people" in *Paid by* lists every member with an amount box. Empty boxes show
|
||||
the unassigned remainder as a placeholder, a live line reads "Remaining" /
|
||||
"Over by" / "Adds up to the total", and the expense list shows "N payers".
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -262,8 +265,8 @@ the minimum in practice, and is easy to reason about.
|
|||
- Create group: name, base currency (default by locale: CZK for Czech, EUR
|
||||
otherwise), icon/emoji, initial members.
|
||||
- Share: copy link, native share sheet, QR code.
|
||||
- Settings: rename, members, "who am I", remove from device, export, delete
|
||||
group (see 8.3).
|
||||
- Settings: rename, members, "who am I", default category, remove from
|
||||
device, export, delete group (see 8.3).
|
||||
- **Base currency is locked once the group has any expense or transfer.** It
|
||||
can be changed freely while the group is empty; afterwards the setting is
|
||||
read-only with a short explanation. Clients enforce this during replay too:
|
||||
|
|
@ -278,6 +281,18 @@ the minimum in practice, and is easy to reason about.
|
|||
the daily rate for the expense date and is editable.
|
||||
- Split editor: equal / shares / exact / percent tabs; tap to exclude people;
|
||||
live "remaining to assign" indicator for exact and percent modes.
|
||||
- The add sheet fits one phone screen (390×844, three members): currency as a
|
||||
pill beside the amount; categories as 12 equal icon tiles (6 × 2 on phones,
|
||||
one row of 12 when wider) with the chosen name beside the label; date and
|
||||
payer side by side ("Several people" is the last payer option); photo, note
|
||||
and repeat stay folded behind small buttons; Save is pinned to the bottom.
|
||||
- Touch gestures on the group page (shortcuts; every action also has a
|
||||
button): pull up past the end of the Expenses or Balances tab to add an
|
||||
expense (a "Pull up to add expense" pill rises from behind the tab bar and
|
||||
reads "Release to add" once far enough; at the bottom so the browser's
|
||||
pull-to-refresh still works), and swipe left/right to move between the
|
||||
Expenses, Balances, Stats and Activity tabs. Swipes starting within 24px
|
||||
of the screen edge are left to the OS back gesture.
|
||||
- **One photo per expense** (receipt), see 9.
|
||||
- Category, date, note.
|
||||
- Comments thread on each expense.
|
||||
|
|
@ -288,6 +303,12 @@ Fixed v1 set with icons: food & drink, groceries, transport, accommodation,
|
|||
entertainment, shopping, utilities, rent, travel, gifts, health, other.
|
||||
Transfers have their own implicit category.
|
||||
|
||||
Each group has a **default category** (`group.updated` → `defaultCategory`,
|
||||
one of the set above; absent means "other") that new expenses start with.
|
||||
Replay ignores a `group.updated` whose `defaultCategory` isn't in the set,
|
||||
without applying any other field of that event. Each category has an icon
|
||||
colour (`CATEGORY_COLORS` in `apps/web/src/lib/format.ts`).
|
||||
|
||||
### 7.4 Recurring expenses
|
||||
|
||||
- A template (expense object + rule: weekly / monthly / yearly, interval,
|
||||
|
|
@ -435,11 +456,22 @@ which group ids exist.
|
|||
|
||||
1. **Home**: groups saved on this device, each showing my balance. "New
|
||||
group", "Open link/scan QR".
|
||||
2. **Group**: tabs: Expenses · Balances (settle up) · Stats · Activity.
|
||||
Floating "+" button for a new expense.
|
||||
2. **Group**: on Expenses and Balances, a header with my balance as the
|
||||
headline number ("You're owed / You owe / settled up"; the group total if
|
||||
"who am I" isn't set), the group's total spent, and round quick actions:
|
||||
Add · Payment · Settle up · Share. Tabs: Expenses · Balances (settle up) ·
|
||||
Stats · Activity. A floating "+" appears only once the quick actions have
|
||||
scrolled off screen. Touch gestures: pull up at the end of the page to
|
||||
add, swipe sideways to change tab (see 7.2).
|
||||
3. **Expense editor** (sheet on mobile, dialog on desktop).
|
||||
4. **Expense detail**: photo, split breakdown, comments, history.
|
||||
5. **Group settings**.
|
||||
5. **Group settings**, kept short: Share (copy link, native share, QR),
|
||||
Group (icon, name, main currency and default category side by side; Save
|
||||
appears only when something changed), Members ("You are" picker on top;
|
||||
rename/archive as icon buttons; add member as the last row),
|
||||
Notifications (one switch; hidden where push isn't available), Repeating
|
||||
expenses (only when there are any), Export, Danger zone (delete asks for
|
||||
the group name only after it is tapped).
|
||||
6. **App settings**: language, theme, notifications.
|
||||
|
||||
### 10.3 Language
|
||||
|
|
|
|||
|
|
@ -70,6 +70,7 @@
|
|||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
svg { flex-shrink: 0; } /* icons beside wrapping text must not be squashed */
|
||||
html { -webkit-text-size-adjust: 100%; }
|
||||
body {
|
||||
margin: 0;
|
||||
|
|
@ -82,7 +83,8 @@ body {
|
|||
h1, h2, h3 { line-height: 1.2; margin: 0; }
|
||||
h1 { font-size: 1.35rem; }
|
||||
h2 { font-size: 1.05rem; }
|
||||
h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
|
||||
h3 { font-size: 1.05rem; font-weight: 700; letter-spacing: -0.01em; }
|
||||
h3.day { font-size: 0.85rem; font-weight: 600; letter-spacing: 0; color: var(--muted); padding-left: 4px; }
|
||||
a { color: var(--accent); }
|
||||
p { margin: 0; }
|
||||
.muted { color: var(--muted); }
|
||||
|
|
@ -145,6 +147,8 @@ button, .btn {
|
|||
.btn.primary:hover { filter: brightness(1.08); }
|
||||
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
|
||||
.btn.ghost { background: transparent; border-color: transparent; }
|
||||
.btn.tint { background: color-mix(in srgb, var(--accent) 15%, var(--surface)); border-color: transparent; color: var(--accent); }
|
||||
.btn.tint:hover { background: color-mix(in srgb, var(--accent) 24%, var(--surface)); }
|
||||
.btn.small { min-height: 34px; padding: 0 14px; font-size: 0.9rem; }
|
||||
.btn.block { width: 100%; }
|
||||
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
|
|
@ -166,9 +170,13 @@ input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-vi
|
|||
input[type='checkbox'] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); flex-shrink: 0; }
|
||||
input[type='date'] { min-width: 0; }
|
||||
|
||||
.seg { display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 3px; }
|
||||
.seg {
|
||||
display: flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 3px;
|
||||
overflow-x: auto; scrollbar-width: none; /* very narrow screens scroll rather than wrap */
|
||||
}
|
||||
.seg::-webkit-scrollbar { display: none; }
|
||||
.seg button {
|
||||
flex: 1; min-height: 38px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-weight: 600; font-size: 0.9rem; padding: 0 8px;
|
||||
flex: 1 0 auto; white-space: nowrap; min-height: 38px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-weight: 600; font-size: 0.9rem; padding: 0 8px;
|
||||
}
|
||||
.seg button[aria-pressed='true'] { background: var(--surface-2); color: var(--text); }
|
||||
|
||||
|
|
@ -223,6 +231,11 @@ dialog.sheet {
|
|||
padding: 0; border: 0; color: var(--text); background: var(--bg);
|
||||
width: 100%; max-width: 100%; height: 100%; max-height: 100%; margin: 0;
|
||||
}
|
||||
dialog.sheet:focus { outline: none; }
|
||||
/* Sheets scroll under an opaque header (and, in the editor, a pinned Save bar):
|
||||
keep focused fields clear of both. */
|
||||
dialog.sheet { scroll-padding: 72px 0 96px; }
|
||||
dialog.sheet .topbar { background: var(--bg); }
|
||||
dialog.sheet::backdrop { background: rgb(0 0 0 / 0.5); }
|
||||
@media (min-width: 760px) {
|
||||
dialog.sheet {
|
||||
|
|
@ -254,3 +267,10 @@ dialog.sheet::backdrop { background: rgb(0 0 0 / 0.5); }
|
|||
.fab { bottom: 32px; right: max(32px, calc(50% - 560px + 32px)); }
|
||||
.page { padding-bottom: 48px; }
|
||||
}
|
||||
|
||||
/* round category icon tinted with its category colour (set --cat inline) */
|
||||
.cat-icon { background: color-mix(in srgb, var(--cat, var(--muted)) 24%, var(--surface-2)); }
|
||||
|
||||
/* money with the whole number emphasised (see moneyParts) */
|
||||
.money .cur, .money .frac { color: var(--muted); font-size: 0.82em; font-weight: inherit; }
|
||||
.pos .money .cur, .pos .money .frac, .neg .money .cur, .neg .money .frac { color: inherit; opacity: 0.8; }
|
||||
|
|
|
|||
|
|
@ -42,14 +42,14 @@
|
|||
<div class="list">
|
||||
{#each members as { m, i, bal } (m.id)}
|
||||
<div class="item">
|
||||
<Avatar member={m} index={i} size={32} />
|
||||
<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'}">
|
||||
<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>
|
||||
|
|
@ -62,12 +62,18 @@
|
|||
{: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" style:font-weight="700">{conv(tr.amount)}</span>
|
||||
<span class="num sub" style:display="block">{conv(tr.amount)}</span>
|
||||
</span>
|
||||
<button class="btn small" onclick={() => record(tr.from, tr.to, tr.amount)}>{t('mark_paid')}</button>
|
||||
<button class="btn small tint" onclick={() => record(tr.from, tr.to, tr.amount)}>{t('mark_paid')}</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
|
@ -85,7 +91,10 @@
|
|||
</div>
|
||||
|
||||
<style>
|
||||
.bar { display: block; height: 6px; margin-top: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
|
||||
.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); }
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { inBase, owedOriginal, type Expense } from '@oweme/core';
|
||||
import { randomId } from '../lib/crypto.ts';
|
||||
import { CATEGORY_ICONS, fmtDate, fmtDateTime, money } from '../lib/format.ts';
|
||||
import { CATEGORY_COLORS, CATEGORY_ICONS, fmtDate, fmtDateTime, money } from '../lib/format.ts';
|
||||
import type { MsgKey } from '../lib/i18n.ts';
|
||||
import { router } from '../lib/router.svelte.ts';
|
||||
import type { GroupSession } from '../lib/session.svelte.ts';
|
||||
|
|
@ -82,7 +82,7 @@
|
|||
{/if}
|
||||
|
||||
<div class="card stack" style:align-items="center" style:text-align="center">
|
||||
<span class="cat-icon" aria-hidden="true">{CATEGORY_ICONS[e.category]}</span>
|
||||
<span class="cat-icon" style:--cat={CATEGORY_COLORS[e.category]} aria-hidden="true">{CATEGORY_ICONS[e.category]}</span>
|
||||
<div class="num" style:font-size="2rem" style:font-weight="700">{money(e.amount, e.currency)}</div>
|
||||
{#if e.currency !== session.base}
|
||||
<div class="muted small num">{t('converted', { amount: money(b.total, session.base), rate: e.rate })}</div>
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { tick, untrack } from 'svelte';
|
||||
import {
|
||||
CATEGORIES, exponent, isValidRate, owedOriginal, parseAmount, validateExpense,
|
||||
type Category, type Expense, type Freq, type Photo, type SplitMode,
|
||||
} from '@oweme/core';
|
||||
import { serverConfig } from '../lib/api.ts';
|
||||
import { randomId } from '../lib/crypto.ts';
|
||||
import { amountInput, CATEGORY_ICONS, fmtDate, money, today } from '../lib/format.ts';
|
||||
import { amountInput, CATEGORY_COLORS, CATEGORY_ICONS, fmtDate, money, today } from '../lib/format.ts';
|
||||
import { processPhoto, type ProcessedPhoto } from '../lib/photo.ts';
|
||||
import { suggestRate } from '../lib/rates.ts';
|
||||
import { router } from '../lib/router.svelte.ts';
|
||||
|
|
@ -15,6 +15,7 @@
|
|||
import type { MsgKey } from '../lib/i18n.ts';
|
||||
import Avatar from './Avatar.svelte';
|
||||
import CurrencySelect from './CurrencySelect.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
import PhotoView from './PhotoView.svelte';
|
||||
import Sheet from './Sheet.svelte';
|
||||
|
||||
|
|
@ -38,7 +39,7 @@
|
|||
let currency = $state(existing?.currency ?? base);
|
||||
let amountText = $state(existing ? amountInput(existing.amount, existing.currency) : pAmount > 0 ? amountInput(pAmount, base) : '');
|
||||
let title = $state(existing?.title ?? '');
|
||||
let category = $state<Category>(existing?.category === 'transfer' ? 'other' : (existing?.category ?? 'food'));
|
||||
let category = $state<Category>(existing?.category === 'transfer' ? 'other' : (existing?.category ?? session.state.group?.defaultCategory ?? 'other'));
|
||||
let date = $state(existing?.date ?? today());
|
||||
let note = $state(existing?.note ?? '');
|
||||
let rateText = $state(existing && existing.currency !== base ? existing.rate : '1');
|
||||
|
|
@ -78,6 +79,12 @@
|
|||
let newPhotoUrl = $state<string | null>(null);
|
||||
let photoBusy = $state(false);
|
||||
let repeat = $state<'none' | Freq>('none');
|
||||
// Note and repeat are folded into small buttons until used.
|
||||
let showNote = $state(!!existing?.note);
|
||||
let showRepeat = $state(false);
|
||||
let noteEl = $state<HTMLTextAreaElement>();
|
||||
/** "Paid by" value that switches to the several-payers list. */
|
||||
const SEVERAL = '*several';
|
||||
let error = $state('');
|
||||
let saving = $state(false);
|
||||
|
||||
|
|
@ -193,6 +200,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
async function openNote() {
|
||||
showNote = true;
|
||||
await tick();
|
||||
noteEl?.focus();
|
||||
}
|
||||
|
||||
function removePhoto() {
|
||||
photo = null;
|
||||
newPhoto = null;
|
||||
|
|
@ -252,117 +265,133 @@
|
|||
</script>
|
||||
|
||||
<Sheet title={heading} onclose={close}>
|
||||
<form class="stack" onsubmit={save} novalidate>
|
||||
<form class="editor" onsubmit={save} novalidate>
|
||||
{#if !existing}
|
||||
<div class="seg" role="group">
|
||||
<div class="seg kind" role="group">
|
||||
<button type="button" aria-pressed={kind === 'expense'} onclick={() => (kind = 'expense')}>{t('kind_expense')}</button>
|
||||
<button type="button" aria-pressed={kind === 'transfer'} onclick={() => (kind = 'transfer')}>{t('kind_transfer')}</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="card stack" style:gap="4px">
|
||||
<label class="sr-only" for="amount">{t('amount')}</label>
|
||||
<input id="amount" class="amount-input num" bind:value={amountText} inputmode="decimal" placeholder={exp === 0 ? '0' : `0${settings.lang === 'cs' ? ',' : '.'}${'0'.repeat(exp)}`} autocomplete="off" />
|
||||
<div class="row" style:justify-content="center">
|
||||
<label class="sr-only" for="currency">{t('currency')}</label>
|
||||
<div style:max-width="260px" style:width="100%"><CurrencySelect id="currency" bind:value={currency} /></div>
|
||||
<!-- amount, with the currency as a pill; the real <select> sits invisibly on top of it -->
|
||||
<div class="card amount-card">
|
||||
<div class="amount-row">
|
||||
<span class="cur-pill">
|
||||
<span aria-hidden="true">{currency}</span><Icon name="down" size={16} />
|
||||
<label class="sr-only" for="currency">{t('currency')}</label>
|
||||
<CurrencySelect id="currency" bind:value={currency} />
|
||||
</span>
|
||||
<label class="sr-only" for="amount">{t('amount')}</label>
|
||||
<input id="amount" class="amount-input num" bind:value={amountText} inputmode="decimal" placeholder={exp === 0 ? '0' : `0${settings.lang === 'cs' ? ',' : '.'}${'0'.repeat(exp)}`} autocomplete="off" />
|
||||
</div>
|
||||
{#if currency !== base}
|
||||
<div class="row small" style:justify-content="center" style:margin-top="6px">
|
||||
<label for="rate" class="muted">1 {currency} =</label>
|
||||
<input id="rate" class="num" style:width="120px" style:min-height="36px" inputmode="decimal" bind:value={rateText}
|
||||
oninput={() => (rateSource = 'manual')} />
|
||||
<span class="muted">{base}</span>
|
||||
<div class="rate">
|
||||
<span class="row small">
|
||||
<label for="rate" class="muted">1 {currency} =</label>
|
||||
<input id="rate" class="num" inputmode="decimal" bind:value={rateText} oninput={() => (rateSource = 'manual')} />
|
||||
<span class="muted">{base}</span>
|
||||
</span>
|
||||
<!-- xr: rates come from ExchangeRate-API's free tier, which requires the attribution link. -->
|
||||
<span class="small muted">
|
||||
{#if rateMissing && rateSource !== 'manual'}{t('rate_unavailable')}
|
||||
{:else if rateSource.startsWith('ecb:')}{t('rate_source_ecb', { date: fmtDate(rateSource.slice(4)) })}
|
||||
{:else if rateSource.startsWith('xr:')}<a href="https://www.exchangerate-api.com" target="_blank" rel="noopener noreferrer">{t('rate_source_xr', { date: fmtDate(rateSource.slice(3)) })}</a>
|
||||
{:else}{t('rate_source_manual')}{/if}
|
||||
{#if amount && isValidRate(rateText.trim().replace(',', '.'))} · ≈ {money(Math.round(amount * Number(rateText.replace(',', '.')) * 10 ** (exponent(base) - exp)), base)}{/if}
|
||||
</span>
|
||||
</div>
|
||||
<!-- xr: rates come from ExchangeRate-API's free tier, which requires the attribution link. -->
|
||||
<p class="small muted" style:text-align="center">
|
||||
{#if rateMissing && rateSource !== 'manual'}{t('rate_unavailable')}
|
||||
{:else if rateSource.startsWith('ecb:')}{t('rate_source_ecb', { date: fmtDate(rateSource.slice(4)) })}
|
||||
{:else if rateSource.startsWith('xr:')}<a href="https://www.exchangerate-api.com" target="_blank" rel="noopener noreferrer">{t('rate_source_xr', { date: fmtDate(rateSource.slice(3)) })}</a>
|
||||
{:else}{t('rate_source_manual')}{/if}
|
||||
{#if amount && isValidRate(rateText.trim().replace(',', '.'))} · ≈ {money(Math.round(amount * Number(rateText.replace(',', '.')) * 10 ** (exponent(base) - exp)), base)}{/if}
|
||||
</p>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if kind === 'expense'}
|
||||
<label class="field">{t('title')}<input bind:value={title} placeholder={t('title_ph')} maxlength="200" /></label>
|
||||
<label class="sr-only" for="title">{t('title')}</label>
|
||||
<input id="title" bind:value={title} placeholder={t('title')} maxlength="200" />
|
||||
|
||||
<!-- 12 equal tiles: 6 × 2 on phones, one row of 12 on wider screens -->
|
||||
<div class="field">
|
||||
<span class="small muted">{t('category')}</span>
|
||||
<div class="chips">
|
||||
<span class="lbl">{t('category')} · <span class="cat-name">{t(`cat_${category}` as MsgKey)}</span></span>
|
||||
<div class="cats" role="group" aria-label={t('category')}>
|
||||
{#each CATEGORIES as c}
|
||||
<button type="button" class="chip" aria-pressed={category === c} onclick={() => (category = c)}>
|
||||
<span aria-hidden="true">{CATEGORY_ICONS[c]}</span> {t(`cat_${c}` as MsgKey)}
|
||||
<button type="button" class="cat" style:--cat={CATEGORY_COLORS[c]} aria-pressed={category === c}
|
||||
aria-label={t(`cat_${c}` as MsgKey)} title={t(`cat_${c}` as MsgKey)} onclick={() => (category = c)}>
|
||||
<span aria-hidden="true">{CATEGORY_ICONS[c]}</span>
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<label class="field">{t('date')}<input type="date" bind:value={date} required /></label>
|
||||
|
||||
<!-- who paid -->
|
||||
{#if kind === 'transfer'}
|
||||
<div class="row">
|
||||
<label class="field" style:flex="1">{t('from_label')}
|
||||
<div class="pair">
|
||||
<label class="field">{t('from_label')}
|
||||
<select bind:value={payer}>{#each members as m}<option value={m.id}>{m.name}</option>{/each}</select>
|
||||
</label>
|
||||
<label class="field" style:flex="1">{t('to_label')}
|
||||
<label class="field">{t('to_label')}
|
||||
<select bind:value={transferTo}>{#each members.filter((m) => m.id !== payer) as m}<option value={m.id}>{m.name}</option>{/each}</select>
|
||||
</label>
|
||||
</div>
|
||||
<label class="field">{t('date')}<input type="date" bind:value={date} required /></label>
|
||||
{:else}
|
||||
<div class="field">
|
||||
<span class="row small muted">
|
||||
<span class="grow" style:flex="1">{t('paid_by_label')}</span>
|
||||
<label class="row" style:gap="6px"><input type="checkbox" bind:checked={multiPayer} /> {t('multiple_payers')}</label>
|
||||
</span>
|
||||
{#if multiPayer}
|
||||
<div class="pair">
|
||||
<label class="field">{t('date')}<input type="date" bind:value={date} required /></label>
|
||||
<label class="field">{t('paid_by_label')}
|
||||
<select aria-label={t('paid_by_label')} bind:value={() => (multiPayer ? SEVERAL : payer), (v) => { multiPayer = v === SEVERAL; if (v !== SEVERAL) payer = v; }}>
|
||||
{#each members as m}<option value={m.id}>{m.name}{m.id === me ? ` (${t('you')})` : ''}</option>{/each}
|
||||
{#if members.length > 1}<option value={SEVERAL}>{t('multiple_payers')}</option>{/if}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{#if multiPayer}
|
||||
<div class="field">
|
||||
<div class="list">
|
||||
{#each members as m (m.id)}
|
||||
<div class="item">
|
||||
<Avatar member={m} index={memberIndex(m.id)} size={30} />
|
||||
<span class="grow">{m.name}</span>
|
||||
<input class="num" style:width="120px" inputmode="decimal" bind:value={payerAmounts[m.id]} aria-label="{t('paid_by_label')}: {m.name}" />
|
||||
<div class="item member">
|
||||
<Avatar member={m} index={memberIndex(m.id)} size={28} />
|
||||
<span class="grow name">{m.name}</span>
|
||||
<!-- empty boxes hint at what's still unassigned -->
|
||||
<input class="num value" inputmode="decimal" bind:value={payerAmounts[m.id]} aria-label="{t('paid_by_label')}: {m.name}"
|
||||
placeholder={payersRemaining > 0 ? amountInput(payersRemaining, currency) : ''} />
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{#if payersRemaining !== 0 && amount}
|
||||
{#if amount && payersRemaining !== 0}
|
||||
<span class="small {payersRemaining < 0 ? 'neg' : 'muted'}">
|
||||
{payersRemaining > 0 ? t('remaining', { amount: money(payersRemaining, currency) }) : t('over_by', { amount: money(-payersRemaining, currency) })}
|
||||
</span>
|
||||
{:else if amount && payers.length > 1}
|
||||
<span class="small pos row adds-up"><Icon name="check" size={14} />{t('adds_up')}</span>
|
||||
{/if}
|
||||
{:else}
|
||||
<select bind:value={payer} aria-label={t('paid_by_label')}>
|
||||
{#each members as m}<option value={m.id}>{m.name}{m.id === me ? ` (${t('you')})` : ''}</option>{/each}
|
||||
</select>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- split -->
|
||||
<div class="field">
|
||||
<span class="small muted">{t('split')}</span>
|
||||
<div class="seg" role="group" aria-label={t('split')}>
|
||||
<div class="lbl-row">
|
||||
<span class="lbl">{t('split')}</span>
|
||||
<button type="button" class="link" onclick={() => members.forEach((m) => (included[m.id] = true))}>{t('select_all')}</button>
|
||||
<button type="button" class="link" onclick={() => members.forEach((m) => (included[m.id] = false))}>{t('select_none')}</button>
|
||||
</div>
|
||||
<div class="seg modes" role="group" aria-label={t('split')}>
|
||||
{#each [['equal', 'split_equal'], ['shares', 'split_shares'], ['exact', 'split_exact'], ['percent', 'split_percent']] as const as [m, label]}
|
||||
<button type="button" aria-pressed={mode === m} onclick={() => setMode(m)}>{t(label)}</button>
|
||||
{/each}
|
||||
</div>
|
||||
<div class="row small" style:justify-content="flex-end">
|
||||
<button type="button" class="btn ghost small" onclick={() => members.forEach((m) => (included[m.id] = true))}>{t('select_all')}</button>
|
||||
<button type="button" class="btn ghost small" onclick={() => members.forEach((m) => (included[m.id] = false))}>{t('select_none')}</button>
|
||||
</div>
|
||||
<div class="list">
|
||||
{#each members as m (m.id)}
|
||||
<div class="item">
|
||||
<input type="checkbox" bind:checked={included[m.id]} aria-label={m.name} />
|
||||
<Avatar member={m} index={memberIndex(m.id)} size={30} />
|
||||
<span class="grow">
|
||||
<span style:display="block">{m.name}</span>
|
||||
{#if preview[m.id]}<span class="small muted num">{money(preview[m.id], currency)}</span>{/if}
|
||||
</span>
|
||||
<div class="item member" class:off={!included[m.id]}>
|
||||
<input id="inc-{m.id}" type="checkbox" bind:checked={included[m.id]} aria-label={m.name} />
|
||||
<label for="inc-{m.id}" class="grow who">
|
||||
<Avatar member={m} index={memberIndex(m.id)} size={28} />
|
||||
<span class="name">{m.name}</span>
|
||||
</label>
|
||||
<!-- what each person owes; in "Amounts" mode the input already says it -->
|
||||
{#if mode !== 'exact' && preview[m.id]}
|
||||
<span class="num share" class:small={mode !== 'equal'} class:muted={mode !== 'equal'}>{money(preview[m.id], currency)}</span>
|
||||
{/if}
|
||||
{#if mode !== 'equal'}
|
||||
<span class="row" style:gap="4px">
|
||||
<input class="num" style:width={mode === 'exact' ? '110px' : '72px'} inputmode={mode === 'shares' ? 'numeric' : 'decimal'}
|
||||
<span class="row value-wrap">
|
||||
<input class="num value" class:narrow={mode !== 'exact'} inputmode={mode === 'shares' ? 'numeric' : 'decimal'}
|
||||
bind:value={values[m.id]} disabled={!included[m.id]} aria-label="{t('split')}: {m.name}" />
|
||||
{#if mode === 'percent'}<span class="muted">%</span>{/if}
|
||||
</span>
|
||||
|
|
@ -382,29 +411,38 @@
|
|||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- photo -->
|
||||
{#if repeat === 'none'}
|
||||
<div class="field">
|
||||
<span class="small muted">{t('photo')}</span>
|
||||
<!-- extras: photo, note and repeat stay folded away until wanted -->
|
||||
<div class="extras">
|
||||
{#if repeat === 'none'}
|
||||
<label class="btn small">
|
||||
<Icon name="camera" size={16} />{photo || newPhoto ? t('replace_photo') : t('photo')}
|
||||
<input class="sr-only" type="file" accept="image/*" onchange={pickPhoto} disabled={photoBusy} />
|
||||
</label>
|
||||
{/if}
|
||||
{#if !showNote}
|
||||
<button type="button" class="btn small" onclick={openNote}><Icon name="edit" size={16} />{t('note')}</button>
|
||||
{/if}
|
||||
{#if !existing && kind === 'expense' && !showRepeat}
|
||||
<button type="button" class="btn small" onclick={() => (showRepeat = true)}><Icon name="repeat" size={16} />{t('repeat')}</button>
|
||||
{/if}
|
||||
</div>
|
||||
{#if repeat === 'none' && (photo || newPhoto || photoBusy)}
|
||||
<div class="photo">
|
||||
{#if newPhotoUrl}
|
||||
<img class="photo-thumb" src={newPhotoUrl} alt={t('photo')} />
|
||||
{:else if photo}
|
||||
<PhotoView {session} {photo} />
|
||||
{/if}
|
||||
<div class="row">
|
||||
<label class="btn small">
|
||||
{photo || newPhoto ? t('replace_photo') : t('add_photo')}
|
||||
<input class="sr-only" type="file" accept="image/*" onchange={pickPhoto} disabled={photoBusy} />
|
||||
</label>
|
||||
{#if photo || newPhoto}<button type="button" class="btn small ghost" onclick={removePhoto}>{t('remove_photo')}</button>{/if}
|
||||
{#if photoBusy}<span class="small muted">{t('processing_photo')}</span>{/if}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<label class="field">{t('note')}<textarea bind:value={note} maxlength="2000"></textarea></label>
|
||||
|
||||
{#if !existing && kind === 'expense'}
|
||||
{#if showNote}
|
||||
<label class="field">{t('note')}<textarea bind:this={noteEl} bind:value={note} maxlength="2000" rows="2"></textarea></label>
|
||||
{/if}
|
||||
{#if showRepeat && !existing && kind === 'expense'}
|
||||
<label class="field">{t('repeat')}
|
||||
<select bind:value={repeat}>
|
||||
<option value="none">{t('repeat_none')}</option>
|
||||
|
|
@ -415,10 +453,77 @@
|
|||
</label>
|
||||
{/if}
|
||||
|
||||
{#if error}<p class="neg" role="alert">{error}</p>{/if}
|
||||
<div class="row">
|
||||
<button type="button" class="btn" style:flex="1" onclick={close}>{t('cancel')}</button>
|
||||
<button type="submit" class="btn primary" style:flex="2" disabled={saving || photoBusy}>{t('save')}</button>
|
||||
<div class="save-bar">
|
||||
{#if error}<p class="neg" role="alert">{error}</p>{/if}
|
||||
<button type="submit" class="btn primary" disabled={saving || photoBusy}>{t('save')}</button>
|
||||
</div>
|
||||
</form>
|
||||
</Sheet>
|
||||
|
||||
<style>
|
||||
.editor { display: flex; flex-direction: column; gap: 12px; }
|
||||
/* On phones the sheet is full screen: keep Save at the bottom edge. */
|
||||
@media (max-width: 759px) {
|
||||
.editor { min-height: calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
|
||||
}
|
||||
.seg.kind button, .seg.modes button { min-height: 32px; }
|
||||
.seg.modes button { font-size: 0.86rem; padding: 0 6px; }
|
||||
.lbl { font-size: 0.85rem; color: var(--muted); }
|
||||
.cat-name { color: var(--text); font-weight: 600; }
|
||||
.field { display: flex; flex-direction: column; gap: 6px; }
|
||||
|
||||
.amount-card { display: flex; flex-direction: column; gap: 8px; padding: 8px 12px; }
|
||||
.amount-row { display: flex; align-items: center; gap: 12px; }
|
||||
.amount-row .amount-input { flex: 1; min-width: 0; text-align: right; font-size: 2.2rem; min-height: 50px; padding: 0; }
|
||||
.cur-pill {
|
||||
position: relative; flex-shrink: 0; display: inline-flex; align-items: center; gap: 4px;
|
||||
height: 40px; padding: 0 10px 0 14px; border-radius: 999px; background: var(--surface-2); font-weight: 700;
|
||||
}
|
||||
.cur-pill:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
|
||||
.cur-pill :global(select) { position: absolute; inset: 0; opacity: 0; min-height: 0; height: 100%; cursor: pointer; }
|
||||
.rate { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }
|
||||
.rate input { width: 110px; min-height: 34px; padding: 4px 10px; }
|
||||
|
||||
.cats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
|
||||
@media (min-width: 600px) { .cats { grid-template-columns: repeat(12, minmax(0, 1fr)); } }
|
||||
.cat {
|
||||
aspect-ratio: 1; max-height: 56px; display: grid; place-items: center; padding: 0;
|
||||
border: 2px solid transparent; border-radius: 16px; font-size: 1.35rem; cursor: pointer;
|
||||
background: color-mix(in srgb, var(--cat) 14%, var(--surface));
|
||||
transition: background-color 0.12s, border-color 0.12s, transform 0.12s;
|
||||
}
|
||||
.cat span { filter: saturate(0.85); }
|
||||
.cat[aria-pressed='true'] { border-color: var(--cat); background: color-mix(in srgb, var(--cat) 34%, var(--surface)); transform: scale(1.04); }
|
||||
.cat[aria-pressed='true'] span { filter: none; }
|
||||
.cat:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
|
||||
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
|
||||
|
||||
.lbl-row { display: flex; align-items: center; gap: 4px; }
|
||||
.lbl-row .lbl { flex: 1; }
|
||||
.link { border: 0; background: none; color: var(--accent); font: inherit; font-size: 0.85rem; font-weight: 600; padding: 0 8px; cursor: pointer; }
|
||||
|
||||
.member { gap: 10px; padding: 6px 12px; min-height: 46px; }
|
||||
.member.off .who, .member.off .share { opacity: 0.45; }
|
||||
.who { display: flex; align-items: center; gap: 10px; min-width: 0; cursor: pointer; }
|
||||
.name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.share { flex-shrink: 0; }
|
||||
.value-wrap { gap: 4px; flex-shrink: 0; }
|
||||
.value { width: 104px; min-height: 36px; padding: 4px 10px; text-align: right; }
|
||||
.value.narrow { width: 64px; }
|
||||
.value::placeholder { color: var(--muted); opacity: 0.6; }
|
||||
.adds-up { gap: 4px; }
|
||||
|
||||
.extras { display: flex; flex-wrap: wrap; gap: 8px; }
|
||||
.extras .btn { flex: 1 1 auto; gap: 6px; padding: 0 12px; }
|
||||
.photo { display: flex; flex-direction: column; gap: 8px; }
|
||||
.photo .photo-thumb { max-height: 160px; }
|
||||
|
||||
.save-bar {
|
||||
position: sticky; bottom: 0; margin-top: auto; display: flex; flex-direction: column; gap: 8px;
|
||||
padding: 10px 0 calc(2px + env(safe-area-inset-bottom));
|
||||
background: linear-gradient(to bottom, transparent, var(--bg) 14px);
|
||||
}
|
||||
.save-bar .btn { width: 100%; }
|
||||
.save-bar p { margin: 0; }
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
<script lang="ts">
|
||||
import { inBase } from '@oweme/core';
|
||||
import { addDays, CATEGORY_ICONS, fmtDate, money, today } from '../lib/format.ts';
|
||||
import { addDays, CATEGORY_COLORS, CATEGORY_ICONS, fmtDate, money, today } from '../lib/format.ts';
|
||||
import { router } from '../lib/router.svelte.ts';
|
||||
import type { GroupSession } from '../lib/session.svelte.ts';
|
||||
import { t } from '../lib/settings.svelte.ts';
|
||||
import Icon from './Icon.svelte';
|
||||
import Money from './Money.svelte';
|
||||
|
||||
let { session }: { session: GroupSession } = $props();
|
||||
let query = $state('');
|
||||
|
|
@ -24,12 +25,6 @@
|
|||
return groups;
|
||||
});
|
||||
|
||||
const total = $derived(
|
||||
Object.values(session.state.expenses)
|
||||
.filter((r) => !r.deleted && r.expense.kind === 'expense')
|
||||
.reduce((a, r) => a + inBase(r.expense, session.base).total, 0),
|
||||
);
|
||||
|
||||
function dayLabel(d: string) {
|
||||
if (d === today()) return t('today');
|
||||
if (d === addDays(today(), -1)) return t('yesterday');
|
||||
|
|
@ -53,13 +48,6 @@
|
|||
</script>
|
||||
|
||||
<div class="stack">
|
||||
<div class="card row">
|
||||
<div class="grow">
|
||||
<div class="muted small">{t('total_spent')}</div>
|
||||
<div class="num" style:font-size="1.6rem" style:font-weight="700">{money(total, session.base)}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if Object.keys(session.state.expenses).length > 6}
|
||||
<input type="search" bind:value={query} placeholder={t('search')} aria-label={t('search')} />
|
||||
{/if}
|
||||
|
|
@ -70,34 +58,50 @@
|
|||
|
||||
{#each rows as day (day.date)}
|
||||
<section class="stack" style:gap="6px">
|
||||
<h3>{dayLabel(day.date)}</h3>
|
||||
<h3 class="day">{dayLabel(day.date)}</h3>
|
||||
<div class="list">
|
||||
{#each day.items as r (r.expense.id)}
|
||||
{@const e = r.expense}
|
||||
{@const m = mine(e)}
|
||||
<a class="item" href="/g/{session.id}/e/{encodeURIComponent(e.id)}" onclick={(ev) => open(ev, e.id)}>
|
||||
<span class="cat-icon" aria-hidden="true">{CATEGORY_ICONS[e.category] ?? '🧾'}</span>
|
||||
<span class="grow">
|
||||
<span class="title row" style:gap="6px">
|
||||
{#if e.kind === 'transfer'}
|
||||
{t('transfer_line', { from: session.memberName(e.payers[0]?.member), to: session.memberName(e.split.entries.find((x) => x.value > 0)?.member) })}
|
||||
{:else}
|
||||
{e.title}
|
||||
{/if}
|
||||
{#if e.recurringId}<Icon name="repeat" size={14} />{/if}
|
||||
{#if e.photo}<Icon name="camera" size={14} />{/if}
|
||||
<span class="cat-icon" style:--cat={CATEGORY_COLORS[e.category]} aria-hidden="true">{CATEGORY_ICONS[e.category] ?? '🧾'}</span>
|
||||
<!-- Two lines, each splitting its width: title | amount, then payer | your part.
|
||||
Keeps the title readable on narrow phones. -->
|
||||
<span class="grow lines">
|
||||
<span class="line">
|
||||
<span class="title grow">
|
||||
<span class="ellipsis">
|
||||
{#if e.kind === 'transfer'}
|
||||
{t('transfer_line', { from: session.memberName(e.payers[0]?.member), to: session.memberName(e.split.entries.find((x) => x.value > 0)?.member) })}
|
||||
{:else}
|
||||
{e.title}
|
||||
{/if}
|
||||
</span>
|
||||
{#if e.recurringId}<Icon name="repeat" size={14} />{/if}
|
||||
{#if e.photo}<Icon name="camera" size={14} />{/if}
|
||||
</span>
|
||||
<span class="amt"><Money minor={e.amount} currency={e.currency} /></span>
|
||||
</span>
|
||||
<span class="sub" style:display="block">
|
||||
{e.payers.length === 1 ? t('paid_by', { name: session.memberName(e.payers[0].member) }) : t('paid_by_many', { n: e.payers.length })}
|
||||
<span class="line">
|
||||
<span class="sub grow">
|
||||
{e.payers.length === 1 ? t('paid_by', { name: session.memberName(e.payers[0].member) }) : t('paid_by_many', { n: e.payers.length })}
|
||||
</span>
|
||||
{#if m}<span class="small num mine {m.cls}">{m.text}</span>{/if}
|
||||
</span>
|
||||
</span>
|
||||
<span class="end">
|
||||
<span class="num" style:display="block" style:font-weight="600">{money(e.amount, e.currency)}</span>
|
||||
{#if m}<span class="small num {m.cls}" style:display="block">{m.text}</span>{/if}
|
||||
</span>
|
||||
</a>
|
||||
{/each}
|
||||
</div>
|
||||
</section>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.lines { display: flex; flex-direction: column; gap: 2px; }
|
||||
.line { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
|
||||
.title { display: flex; align-items: center; gap: 6px; min-width: 0; }
|
||||
.title :global(svg) { color: var(--muted); }
|
||||
.ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.amt { flex-shrink: 0; font-weight: 650; }
|
||||
.mine { flex-shrink: 0; white-space: nowrap; } /* your part matters more than who paid */
|
||||
</style>
|
||||
|
|
|
|||
215
apps/web/src/components/GroupGestures.svelte
Normal file
215
apps/web/src/components/GroupGestures.svelte
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<script lang="ts">
|
||||
// Touch gestures on the group page (shortcuts; every action also has a button):
|
||||
// - Pull up past the end of the page: a pill rises from behind the tab bar;
|
||||
// letting go once it reads "Release to add" opens the add-expense sheet.
|
||||
// Bottom rather than top, so the browser's pull-to-refresh keeps working.
|
||||
// - Swipe sideways: previous / next tab. Touches near the screen edges are
|
||||
// left to the OS back/forward gestures.
|
||||
import { t } from '../lib/settings.svelte.ts';
|
||||
import Icon from './Icon.svelte';
|
||||
|
||||
const {
|
||||
enabled,
|
||||
addEnabled,
|
||||
tabs,
|
||||
current,
|
||||
onadd,
|
||||
ontab,
|
||||
}: {
|
||||
/** Gestures at all (off while a sheet or the identity picker is open). */
|
||||
enabled: boolean;
|
||||
/** Pull-up-to-add on this tab. */
|
||||
addEnabled: boolean;
|
||||
tabs: readonly string[];
|
||||
current: string;
|
||||
onadd: () => void;
|
||||
ontab: (key: string, dir: 1 | -1) => void;
|
||||
} = $props();
|
||||
|
||||
/** How far the pill must rise (after resistance) before a release adds. */
|
||||
const THRESHOLD = 72;
|
||||
const MAX = 110;
|
||||
/** Finger movement before we decide which gesture this is. */
|
||||
const SLOP = 10;
|
||||
/** Touches starting this close to the left/right edge belong to the OS. */
|
||||
const EDGE = 24;
|
||||
|
||||
let pull = $state(0);
|
||||
let bottom = $state(0);
|
||||
let releasing = $state(false);
|
||||
const armed = $derived(pull >= THRESHOLD);
|
||||
|
||||
const atBottom = () => window.scrollY + window.innerHeight >= document.documentElement.scrollHeight - 2;
|
||||
|
||||
/** True if the touch starts inside something that scrolls sideways itself. */
|
||||
function inHorizontalScroller(el: Element | null): boolean {
|
||||
for (; el && el !== document.body; el = el.parentElement) {
|
||||
const ox = getComputedStyle(el).overflowX;
|
||||
if ((ox === 'auto' || ox === 'scroll') && el.scrollWidth > el.clientWidth) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (!enabled) return;
|
||||
// Read props through closures so the listeners always see current values
|
||||
// without being re-attached on every tab change.
|
||||
const add = () => addEnabled;
|
||||
const tabList = () => tabs;
|
||||
const cur = () => current;
|
||||
|
||||
type Track = { x: number; y: number; t: number; mode: 'undecided' | 'add' | 'swipe'; canAdd: boolean; canSwipe: boolean };
|
||||
let tr: Track | null = null;
|
||||
let wasArmed = false;
|
||||
const page = () => document.querySelector<HTMLElement>('.layout');
|
||||
|
||||
function neighbour(dir: 1 | -1): string | undefined {
|
||||
const list = tabList();
|
||||
return list[list.indexOf(cur()) + dir];
|
||||
}
|
||||
|
||||
function resetPull() {
|
||||
releasing = true;
|
||||
pull = 0;
|
||||
wasArmed = false;
|
||||
}
|
||||
|
||||
function resetSwipe(el: HTMLElement | null) {
|
||||
if (!el) return;
|
||||
el.style.transition = 'transform 0.2s ease';
|
||||
el.style.transform = '';
|
||||
el.addEventListener('transitionend', () => (el.style.transition = ''), { once: true });
|
||||
}
|
||||
|
||||
const onStart = (e: TouchEvent) => {
|
||||
tr = null;
|
||||
if (e.touches.length !== 1) return;
|
||||
const target = e.target as Element | null;
|
||||
if (target?.closest('input, textarea, select, dialog')) return;
|
||||
const tch = e.touches[0];
|
||||
const nearEdge = tch.clientX < EDGE || tch.clientX > window.innerWidth - EDGE;
|
||||
tr = {
|
||||
x: tch.clientX, y: tch.clientY, t: e.timeStamp, mode: 'undecided',
|
||||
canAdd: add() && atBottom(),
|
||||
canSwipe: !nearEdge && !inHorizontalScroller(target),
|
||||
};
|
||||
if (tr.canAdd) {
|
||||
const bar = document.querySelector('.tabbar')?.getBoundingClientRect();
|
||||
// The tab bar floats at the bottom on phones; the pill hides behind it.
|
||||
bottom = bar && getComputedStyle(document.querySelector('.tabbar')!).position === 'fixed'
|
||||
? window.innerHeight - bar.top + 8 : 16;
|
||||
}
|
||||
};
|
||||
|
||||
const onMove = (e: TouchEvent) => {
|
||||
if (!tr) return;
|
||||
const tch = e.touches[0];
|
||||
const dx = tch.clientX - tr.x;
|
||||
const dy = tch.clientY - tr.y;
|
||||
if (tr.mode === 'undecided') {
|
||||
if (Math.abs(dx) < SLOP && Math.abs(dy) < SLOP) return;
|
||||
if (tr.canSwipe && Math.abs(dx) > Math.abs(dy) * 1.2) tr.mode = 'swipe';
|
||||
else if (tr.canAdd && dy < 0 && Math.abs(dy) > Math.abs(dx) && atBottom()) {
|
||||
tr.mode = 'add';
|
||||
releasing = false;
|
||||
} else {
|
||||
tr = null; // ordinary scrolling
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (e.cancelable) e.preventDefault();
|
||||
if (tr.mode === 'add') {
|
||||
pull = Math.min(MAX, Math.max(0, -dy - SLOP) * 0.55);
|
||||
const nowArmed = pull >= THRESHOLD;
|
||||
if (nowArmed && !wasArmed) navigator.vibrate?.(10);
|
||||
wasArmed = nowArmed;
|
||||
} else {
|
||||
const el = page();
|
||||
if (!el) return;
|
||||
// Rubber-band at the first and last tab.
|
||||
const free = neighbour(dx < 0 ? 1 : -1) !== undefined;
|
||||
const shift = free ? dx * 0.6 : dx * 0.15;
|
||||
el.style.transition = '';
|
||||
el.style.transform = `translateX(${shift}px)`;
|
||||
}
|
||||
};
|
||||
|
||||
const onEnd = (e: TouchEvent) => {
|
||||
if (!tr) return;
|
||||
const t0 = tr;
|
||||
tr = null;
|
||||
if (t0.mode === 'add') {
|
||||
const go = pull >= THRESHOLD;
|
||||
resetPull();
|
||||
if (go) onadd();
|
||||
} else if (t0.mode === 'swipe') {
|
||||
const tch = e.changedTouches[0];
|
||||
const dx = tch.clientX - t0.x;
|
||||
const speed = Math.abs(dx) / Math.max(1, e.timeStamp - t0.t);
|
||||
const dir: 1 | -1 = dx < 0 ? 1 : -1;
|
||||
const next = neighbour(dir);
|
||||
const el = page();
|
||||
if (next && (Math.abs(dx) > window.innerWidth * 0.25 || (Math.abs(dx) > 40 && speed > 0.4))) {
|
||||
if (el) { el.style.transition = ''; el.style.transform = ''; }
|
||||
ontab(next, dir);
|
||||
} else {
|
||||
resetSwipe(el);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const onCancel = () => {
|
||||
if (tr?.mode === 'add') resetPull();
|
||||
if (tr?.mode === 'swipe') resetSwipe(page());
|
||||
tr = null;
|
||||
};
|
||||
|
||||
window.addEventListener('touchstart', onStart, { passive: true });
|
||||
window.addEventListener('touchmove', onMove, { passive: false });
|
||||
window.addEventListener('touchend', onEnd);
|
||||
window.addEventListener('touchcancel', onCancel);
|
||||
return () => {
|
||||
window.removeEventListener('touchstart', onStart);
|
||||
window.removeEventListener('touchmove', onMove);
|
||||
window.removeEventListener('touchend', onEnd);
|
||||
window.removeEventListener('touchcancel', onCancel);
|
||||
const el = page();
|
||||
if (el) el.style.transform = '';
|
||||
pull = 0;
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<div
|
||||
class="pull"
|
||||
class:armed
|
||||
class:releasing
|
||||
aria-hidden="true"
|
||||
style:bottom="{bottom}px"
|
||||
style:transform="translate(-50%, {48 - pull}px)"
|
||||
style:opacity={Math.min(1, pull / 32)}
|
||||
>
|
||||
<span class="c"><Icon name={armed ? 'plus' : 'up'} size={18} /></span>
|
||||
{armed ? t('release_to_add') : t('pull_to_add')}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.pull {
|
||||
position: fixed; left: 50%; z-index: 19; pointer-events: none;
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 6px 14px 6px 6px; border-radius: 999px;
|
||||
background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
|
||||
color: var(--muted); font-size: 0.88rem; font-weight: 600; white-space: nowrap;
|
||||
opacity: 0;
|
||||
}
|
||||
.c {
|
||||
display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
|
||||
background: var(--surface-2); color: var(--text);
|
||||
}
|
||||
.armed { color: var(--text); }
|
||||
.armed .c { background: var(--accent); color: var(--accent-ink); }
|
||||
.releasing { transition: transform 0.2s ease, opacity 0.2s ease; }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.releasing { transition: none; }
|
||||
}
|
||||
</style>
|
||||
74
apps/web/src/components/GroupHeader.svelte
Normal file
74
apps/web/src/components/GroupHeader.svelte
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
<script lang="ts">
|
||||
// Top of the group page: your balance as the headline number, the group's
|
||||
// total, and round quick actions. Reports whether the actions are on
|
||||
// screen so the page can show the floating Add button only when they aren't.
|
||||
import { inBase } from '@oweme/core';
|
||||
import { router } from '../lib/router.svelte.ts';
|
||||
import type { GroupSession } from '../lib/session.svelte.ts';
|
||||
import { t } from '../lib/settings.svelte.ts';
|
||||
import Icon from './Icon.svelte';
|
||||
import Money from './Money.svelte';
|
||||
|
||||
let { session, onactionsvisible }: { session: GroupSession; onactionsvisible: (visible: boolean) => void } = $props();
|
||||
const base = $derived(`/g/${session.id}`);
|
||||
|
||||
const total = $derived(
|
||||
Object.values(session.state.expenses)
|
||||
.filter((r) => !r.deleted && r.expense.kind === 'expense')
|
||||
.reduce((a, r) => a + inBase(r.expense, session.base).total, 0),
|
||||
);
|
||||
const mine = $derived(session.me ? (session.balances[session.me] ?? 0) : null);
|
||||
|
||||
function go(e: MouseEvent, path: string, replace = false) {
|
||||
e.preventDefault();
|
||||
router.go(path, { replace });
|
||||
}
|
||||
|
||||
let actions: HTMLElement;
|
||||
$effect(() => {
|
||||
const io = new IntersectionObserver(([entry]) => onactionsvisible(entry.isIntersecting));
|
||||
io.observe(actions);
|
||||
return () => io.disconnect();
|
||||
});
|
||||
</script>
|
||||
|
||||
<section class="hero" aria-label={t('summary')}>
|
||||
{#if mine === null}
|
||||
<div class="lbl">{t('total_spent')}</div>
|
||||
<div class="big"><Money minor={total} currency={session.base} /></div>
|
||||
{:else}
|
||||
<div class="lbl">{mine > 0 ? t('hero_owed') : mine < 0 ? t('hero_owe') : t('hero_settled')}</div>
|
||||
<div class="big {mine > 0 ? 'pos' : mine < 0 ? 'neg' : ''}"><Money minor={Math.abs(mine)} currency={session.base} /></div>
|
||||
<div class="meta"><span class="dot" aria-hidden="true"></span>{t('total_spent')} <Money minor={total} currency={session.base} /></div>
|
||||
{/if}
|
||||
</section>
|
||||
|
||||
<nav class="actions" bind:this={actions} aria-label={t('quick_actions')}>
|
||||
<a class="act primary" href="{base}/e/new" onclick={(e) => go(e, `${base}/e/new`)} aria-label={t('add_expense')}><span class="c"><Icon name="plus" /></span>{t('add')}</a>
|
||||
<a class="act" href="{base}/e/new?kind=transfer" onclick={(e) => go(e, `${base}/e/new?kind=transfer`)} aria-label={t('add_payment')}><span class="c"><Icon name="swap" /></span>{t('payment_short')}</a>
|
||||
<a class="act" href="{base}/balances" onclick={(e) => go(e, `${base}/balances`, true)}><span class="c"><Icon name="scale" /></span>{t('settle_up')}</a>
|
||||
<a class="act" href="{base}/settings" onclick={(e) => go(e, `${base}/settings`)}><span class="c"><Icon name="share" /></span>{t('share_short')}</a>
|
||||
</nav>
|
||||
|
||||
<style>
|
||||
.hero { text-align: center; padding: 8px 0 0; }
|
||||
.lbl { color: var(--muted); font-size: 0.92rem; font-weight: 500; }
|
||||
.big { font-size: 2.75rem; font-weight: 750; letter-spacing: -0.03em; line-height: 1.15; margin: 2px 0; overflow-wrap: anywhere; }
|
||||
.big :global(.cur), .big :global(.frac) { font-size: 0.55em; letter-spacing: -0.01em; }
|
||||
.meta {
|
||||
display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; padding: 6px 12px; border-radius: 999px;
|
||||
background: var(--surface); color: var(--muted); font-size: 0.84rem; font-weight: 500;
|
||||
}
|
||||
.meta :global(.money), .meta :global(.money .cur), .meta :global(.money .frac) { color: var(--text); font-size: 1em; }
|
||||
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
|
||||
.actions { display: flex; justify-content: center; gap: 8px; padding: 14px 0 4px; }
|
||||
.act {
|
||||
flex: 0 1 84px; display: flex; flex-direction: column; align-items: center; gap: 7px; text-align: center;
|
||||
font-size: 0.8rem; font-weight: 600; color: var(--text); text-decoration: none; line-height: 1.2;
|
||||
}
|
||||
.act .c { width: 52px; height: 52px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; }
|
||||
.act.primary .c { background: var(--accent); color: var(--accent-ink); }
|
||||
.act:hover .c { filter: brightness(1.12); }
|
||||
.act:focus-visible { outline: none; }
|
||||
.act:focus-visible .c { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
</style>
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { onDestroy, untrack } from 'svelte';
|
||||
import { onDestroy, tick, untrack } from 'svelte';
|
||||
import { forgetGroup } from '../lib/idb.ts';
|
||||
import { router } from '../lib/router.svelte.ts';
|
||||
import { closeSession, openSession, type GroupSession } from '../lib/session.svelte.ts';
|
||||
|
|
@ -9,9 +9,11 @@
|
|||
import ExpenseDetail from './ExpenseDetail.svelte';
|
||||
import ExpenseEditor from './ExpenseEditor.svelte';
|
||||
import ExpenseList from './ExpenseList.svelte';
|
||||
import GroupHeader from './GroupHeader.svelte';
|
||||
import GroupSettings from './GroupSettings.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
import IdentityPicker from './IdentityPicker.svelte';
|
||||
import GroupGestures from './GroupGestures.svelte';
|
||||
import Stats from './Stats.svelte';
|
||||
|
||||
// Keyed by group id in App.svelte, so reading it once is enough.
|
||||
|
|
@ -19,12 +21,16 @@
|
|||
const id = untrack(() => props.id);
|
||||
let session = $state<GroupSession | null | undefined>(undefined);
|
||||
let skippedIdentity = $state(false);
|
||||
// The floating Add button only appears once the header's actions scroll away.
|
||||
// Starts true so the button doesn't flash before the observer reports.
|
||||
let actionsVisible = $state(true);
|
||||
|
||||
openSession(id).then((s) => (session = s));
|
||||
onDestroy(() => closeSession(id));
|
||||
|
||||
const route = $derived(router.route);
|
||||
const tab = $derived(route.name === 'group' ? route.tab : 'expenses');
|
||||
const withHeader = $derived(tab === 'expenses' || tab === 'balances');
|
||||
const base = `/g/${id}`;
|
||||
const tabs = [
|
||||
{ key: 'expenses', path: base, icon: 'list', label: 'expenses' },
|
||||
|
|
@ -42,6 +48,18 @@
|
|||
!!session && session.status !== 'loading' && session.state.members.length > 0 && !session.me && !skippedIdentity,
|
||||
);
|
||||
|
||||
/** Tab change from a swipe: the new tab slides in from the side it came from. */
|
||||
async function switchTab(key: string, dir: 1 | -1) {
|
||||
const path = tabs.find((x) => x.key === key)!.path;
|
||||
router.go(path, { replace: true });
|
||||
await tick();
|
||||
if (matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
||||
document.querySelector('.layout')?.animate(
|
||||
[{ transform: `translateX(${dir * 48}px)`, opacity: 0.4 }, { transform: 'none', opacity: 1 }],
|
||||
{ duration: 180, easing: 'ease-out' },
|
||||
);
|
||||
}
|
||||
|
||||
async function remove() {
|
||||
await forgetGroup(id);
|
||||
router.go('/', { replace: true });
|
||||
|
|
@ -62,7 +80,8 @@
|
|||
{@const s = session}
|
||||
<header class="topbar">
|
||||
<button class="icon-btn" onclick={() => router.go('/')} aria-label={t('back')}><Icon name="back" /></button>
|
||||
<h1><span aria-hidden="true">{s.state.group?.icon}</span> {s.state.group?.name ?? s.local.name}</h1>
|
||||
{#if s.state.group?.icon}<span class="group-icon" aria-hidden="true">{s.state.group.icon}</span>{/if}
|
||||
<h1>{s.state.group?.name ?? s.local.name}</h1>
|
||||
<a class="icon-btn" href="{base}/settings" onclick={(e) => nav(e, `${base}/settings`)} aria-label={t('group_settings')}><Icon name="settings" /></a>
|
||||
</header>
|
||||
|
||||
|
|
@ -80,6 +99,10 @@
|
|||
{/if}
|
||||
{#if s.rollback}<p class="banner warn">{t('rollback_warning')}</p>{/if}
|
||||
|
||||
{#if withHeader && s.status !== 'gone'}
|
||||
<GroupHeader session={s} onactionsvisible={(v) => (actionsVisible = v)} />
|
||||
{/if}
|
||||
|
||||
<nav class="tabbar" aria-label={s.state.group?.name}>
|
||||
{#each tabs as tb}
|
||||
<a href={tb.path} aria-current={tab === tb.key ? 'page' : undefined} onclick={(e) => nav(e, tb.path, true)}>
|
||||
|
|
@ -107,10 +130,19 @@
|
|||
</div>
|
||||
</main>
|
||||
|
||||
{#if s.status !== 'gone' && (tab === 'expenses' || tab === 'balances')}
|
||||
{#if s.status !== 'gone' && withHeader && !actionsVisible}
|
||||
<a class="fab" href="{base}/e/new" onclick={(e) => nav(e, `${base}/e/new`)} aria-label={t('add_expense')}><Icon name="plus" size={28} /></a>
|
||||
{/if}
|
||||
|
||||
<GroupGestures
|
||||
enabled={route.name === 'group' && s.status !== 'gone' && !needsIdentity}
|
||||
addEnabled={withHeader}
|
||||
tabs={tabs.map((x) => x.key)}
|
||||
current={tab}
|
||||
onadd={() => router.go(`${base}/e/new`)}
|
||||
ontab={switchTab}
|
||||
/>
|
||||
|
||||
{#if route.name === 'expense'}
|
||||
<ExpenseDetail session={s} eid={route.eid} />
|
||||
{:else if route.name === 'expense-edit'}
|
||||
|
|
@ -123,7 +155,15 @@
|
|||
{/if}
|
||||
|
||||
<style>
|
||||
.layout { display: grid; gap: 24px; }
|
||||
/* A tab being swiped sideways must not widen the page. */
|
||||
main { overflow-x: clip; }
|
||||
.group-icon {
|
||||
display: grid; place-items: center; flex-shrink: 0; width: 36px; height: 36px; border-radius: 50%;
|
||||
background: var(--surface-2); font-size: 1.1rem;
|
||||
}
|
||||
/* minmax(0, …): without it a long title or name (nowrap + ellipsis) widens
|
||||
the column past the screen and phones zoom out. */
|
||||
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 24px; }
|
||||
.side-col { display: none; }
|
||||
@media (min-width: 960px) {
|
||||
.layout.with-side { grid-template-columns: minmax(0, 1fr) 340px; }
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
<script lang="ts">
|
||||
import { untrack } from 'svelte';
|
||||
import { balancesCsv, expensesCsv, nextOccurrence } from '@oweme/core';
|
||||
import { balancesCsv, CATEGORIES, expensesCsv, nextOccurrence } from '@oweme/core';
|
||||
import { renderSVG } from 'uqr';
|
||||
import { api } from '../lib/api.ts';
|
||||
import { makeBackup } from '../lib/backup.ts';
|
||||
import { randomId } from '../lib/crypto.ts';
|
||||
import { download, fmtDate, MEMBER_COLORS, money, slug, today } from '../lib/format.ts';
|
||||
import { CATEGORY_ICONS, download, fmtDate, MEMBER_COLORS, money, slug, today } from '../lib/format.ts';
|
||||
import type { MsgKey } from '../lib/i18n.ts';
|
||||
import { forgetGroup } from '../lib/idb.ts';
|
||||
import { disablePush, enablePush, pushSupport, type PushSupport } from '../lib/push.ts';
|
||||
import { router } from '../lib/router.svelte.ts';
|
||||
|
|
@ -27,14 +28,19 @@
|
|||
let name = $state(s.state.group?.name ?? '');
|
||||
let icon = $state(s.state.group?.icon ?? '');
|
||||
let baseCurrency = $state(s.base);
|
||||
let defaultCategory = $state<string>(s.state.group?.defaultCategory ?? 'other');
|
||||
let newMember = $state('');
|
||||
let deleteConfirm = $state('');
|
||||
let deleteOpen = $state(false);
|
||||
let push = $state<PushSupport | null>(null);
|
||||
let pushBusy = $state(false);
|
||||
pushSupport().then((p) => (push = p));
|
||||
|
||||
const locked = $derived(Object.keys(s.state.expenses).length > 0);
|
||||
const dirty = $derived(name.trim() !== s.state.group?.name || icon !== s.state.group?.icon || baseCurrency !== s.base);
|
||||
const dirty = $derived(
|
||||
name.trim() !== s.state.group?.name || icon !== s.state.group?.icon || baseCurrency !== s.base ||
|
||||
defaultCategory !== (s.state.group?.defaultCategory ?? 'other'),
|
||||
);
|
||||
|
||||
async function copy() {
|
||||
await navigator.clipboard.writeText(link);
|
||||
|
|
@ -50,10 +56,11 @@
|
|||
async function saveGroup(e: SubmitEvent) {
|
||||
e.preventDefault();
|
||||
if (!name.trim()) return;
|
||||
const data: { name?: string; icon?: string; baseCurrency?: string } = {};
|
||||
const data: { name?: string; icon?: string; baseCurrency?: string; defaultCategory?: (typeof CATEGORIES)[number] } = {};
|
||||
if (name.trim() !== s.state.group?.name) data.name = name.trim();
|
||||
if (icon !== s.state.group?.icon) data.icon = icon;
|
||||
if (!locked && baseCurrency !== s.base) data.baseCurrency = baseCurrency;
|
||||
if (defaultCategory !== (s.state.group?.defaultCategory ?? 'other')) data.defaultCategory = defaultCategory as (typeof CATEGORIES)[number];
|
||||
await s.emit({ type: 'group.updated', data });
|
||||
ui.show(t('saved'));
|
||||
}
|
||||
|
|
@ -117,10 +124,12 @@
|
|||
<div class="card stack">
|
||||
{#if justCreated}<p class="banner warn">{t('save_link_warning')}</p>{/if}
|
||||
<p class="small muted">{t('share_intro')}</p>
|
||||
<div class="row wrap">
|
||||
<button class="btn primary" onclick={copy}><Icon name="copy" size={18} /> {t('copy_link')}</button>
|
||||
{#if 'share' in navigator}<button class="btn" onclick={nativeShare}><Icon name="share" size={18} /> {t('share')}</button>{/if}
|
||||
<button class="btn ghost" onclick={() => (showQr = !showQr)}>QR</button>
|
||||
<div class="row">
|
||||
<button class="btn primary grow" onclick={copy}><Icon name="copy" size={18} /> {t('copy_link')}</button>
|
||||
{#if 'share' in navigator}
|
||||
<button class="btn square" onclick={nativeShare} aria-label={t('share')} title={t('share')}><Icon name="share" size={18} /></button>
|
||||
{/if}
|
||||
<button class="btn square" aria-pressed={showQr} aria-label={t('qr_code')} title={t('qr_code')} onclick={() => (showQr = !showQr)}>QR</button>
|
||||
</div>
|
||||
{#if showQr}
|
||||
<div class="qr">{@html qr}</div>
|
||||
|
|
@ -130,83 +139,82 @@
|
|||
|
||||
<!-- group -->
|
||||
<section class="section">
|
||||
<h3>{t('group_settings')}</h3>
|
||||
<h3>{t('group')}</h3>
|
||||
<form class="card stack" onsubmit={saveGroup}>
|
||||
<div class="row">
|
||||
<label class="field" style:width="80px">{t('icon')}<input bind:value={icon} maxlength="8" /></label>
|
||||
<label class="field" style:width="72px">{t('icon')}<input bind:value={icon} maxlength="8" /></label>
|
||||
<label class="field" style:flex="1">{t('group_name')}<input bind:value={name} maxlength="100" required /></label>
|
||||
</div>
|
||||
<label class="field">
|
||||
{t('base_currency')}
|
||||
<CurrencySelect bind:value={baseCurrency} disabled={locked} />
|
||||
<span class="small">{locked ? t('base_currency_locked') : t('base_currency_hint')}</span>
|
||||
</label>
|
||||
<button class="btn primary" type="submit" disabled={!dirty || !name.trim()}>{t('save')}</button>
|
||||
<div class="pair">
|
||||
<label class="field">
|
||||
{t('base_currency')}
|
||||
<CurrencySelect bind:value={baseCurrency} disabled={locked} />
|
||||
</label>
|
||||
<label class="field">
|
||||
{t('default_category')}
|
||||
<select bind:value={defaultCategory}>
|
||||
{#each CATEGORIES as c}<option value={c}>{CATEGORY_ICONS[c]} {t(`cat_${c}` as MsgKey)}</option>{/each}
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
{#if locked}<p class="small muted">{t('base_currency_locked')}</p>{/if}
|
||||
{#if dirty}<button class="btn primary" type="submit" disabled={!name.trim()}>{t('save')}</button>{/if}
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<!-- identity -->
|
||||
<section class="section">
|
||||
<h3>{t('identity')}</h3>
|
||||
<select value={s.me ?? ''} onchange={(e) => s.setMe((e.target as HTMLSelectElement).value || null)} aria-label={t('identity')}>
|
||||
<option value="">{t('not_set')}</option>
|
||||
{#each s.state.members.filter((m) => !m.archived) as m}<option value={m.id}>{m.name}</option>{/each}
|
||||
</select>
|
||||
</section>
|
||||
|
||||
<!-- members -->
|
||||
<!-- members, with "you are" on top -->
|
||||
<section class="section">
|
||||
<h3>{t('members')}</h3>
|
||||
<div class="list">
|
||||
<div class="item">
|
||||
<span class="grow">{t('identity')}</span>
|
||||
<select class="me" value={s.me ?? ''} onchange={(e) => s.setMe((e.target as HTMLSelectElement).value || null)} aria-label={t('identity')}>
|
||||
<option value="">{t('not_set')}</option>
|
||||
{#each s.state.members.filter((m) => !m.archived) as m}<option value={m.id}>{m.name}</option>{/each}
|
||||
</select>
|
||||
</div>
|
||||
{#each s.state.members as m, i (m.id)}
|
||||
{@const bal = s.balances[m.id] ?? 0}
|
||||
<div class="item">
|
||||
<div class="item" class:archived={m.archived}>
|
||||
<Avatar member={m} index={i} size={32} />
|
||||
<span class="grow">
|
||||
<span class="title" style:display="block">{m.name}{m.archived ? ` · ${t('archived')}` : ''}</span>
|
||||
<span class="title" style:display="block">{m.name}{m.id === s.me ? ` (${t('you')})` : ''}{m.archived ? ` · ${t('archived')}` : ''}</span>
|
||||
<span class="sub num {bal > 0 ? 'pos' : bal < 0 ? 'neg' : ''}">{bal === 0 ? t('settled') : money(bal, s.base, { sign: true })}</span>
|
||||
</span>
|
||||
<button class="btn small ghost" onclick={() => rename(m.id, m.name)}>{t('rename')}</button>
|
||||
<button class="icon-btn" onclick={() => rename(m.id, m.name)} aria-label="{t('rename')}: {m.name}" title={t('rename')}><Icon name="edit" size={18} /></button>
|
||||
{#if m.archived}
|
||||
<button class="btn small ghost" onclick={() => s.emit({ type: 'member.restored', data: { id: m.id } })}>{t('unarchive')}</button>
|
||||
<button class="icon-btn" onclick={() => s.emit({ type: 'member.restored', data: { id: m.id } })} aria-label="{t('unarchive')}: {m.name}" title={t('unarchive')}><Icon name="undo" size={18} /></button>
|
||||
{:else}
|
||||
<button class="btn small ghost" disabled={bal !== 0} title={bal !== 0 ? t('archive_needs_zero') : ''}
|
||||
onclick={() => s.emit({ type: 'member.archived', data: { id: m.id } })}>{t('archive')}</button>
|
||||
<button class="icon-btn" disabled={bal !== 0} aria-label="{t('archive')}: {m.name}" title={bal !== 0 ? t('archive_needs_zero') : t('archive')}
|
||||
onclick={() => s.emit({ type: 'member.archived', data: { id: m.id } })}><Icon name="archive" size={18} /></button>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
<form class="row" onsubmit={addMember}>
|
||||
<input bind:value={newMember} placeholder={t('member_name')} maxlength="60" aria-label={t('member_name')} />
|
||||
<button class="btn" type="submit" disabled={!newMember.trim()}><Icon name="plus" size={18} /> {t('add_member')}</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<!-- notifications -->
|
||||
<section class="section">
|
||||
<h3>{t('notifications')}</h3>
|
||||
<div class="card stack">
|
||||
{#if push === 'ok' || s.local.push}
|
||||
<label class="row">
|
||||
<input type="checkbox" checked={s.local.push} disabled={pushBusy} onchange={togglePush} />
|
||||
<span>{t('notifications_hint')}</span>
|
||||
</label>
|
||||
{:else if push === 'needs-install'}
|
||||
<p class="small">{t('notifications_ios')}</p>
|
||||
{:else if push === 'denied'}
|
||||
<p class="small">{t('notifications_denied')}</p>
|
||||
{:else if push}
|
||||
<p class="small muted">{t('notifications_unavailable')}</p>
|
||||
{/if}
|
||||
<form class="item" onsubmit={addMember}>
|
||||
<input class="bare" bind:value={newMember} placeholder={t('member_name')} maxlength="60" aria-label={t('member_name')} />
|
||||
<button class="btn small" type="submit" disabled={!newMember.trim()}><Icon name="plus" size={16} /> {t('add_member')}</button>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- recurring -->
|
||||
<section class="section">
|
||||
<h3>{t('recurring')}</h3>
|
||||
{#if Object.keys(s.state.recurring).length === 0}
|
||||
<p class="card small muted">{t('no_recurring')}</p>
|
||||
{:else}
|
||||
{#if push === 'ok' || s.local.push}
|
||||
<section class="section">
|
||||
<h3>{t('notifications')}</h3>
|
||||
<label class="list item">
|
||||
<span class="grow">{t('notifications_hint')}</span>
|
||||
<input class="switch" type="checkbox" checked={s.local.push} disabled={pushBusy} onchange={togglePush} />
|
||||
</label>
|
||||
</section>
|
||||
{:else if push === 'needs-install' || push === 'denied'}
|
||||
<section class="section">
|
||||
<h3>{t('notifications')}</h3>
|
||||
<p class="small muted">{push === 'denied' ? t('notifications_denied') : t('notifications_ios')}</p>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
{#if Object.keys(s.state.recurring).length}
|
||||
<section class="section">
|
||||
<h3>{t('recurring')}</h3>
|
||||
<div class="list">
|
||||
{#each Object.values(s.state.recurring) as r (r.id)}
|
||||
{@const next = nextOccurrence(r.rule, today())}
|
||||
|
|
@ -220,16 +228,16 @@
|
|||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</section>
|
||||
</section>
|
||||
{/if}
|
||||
|
||||
<!-- export -->
|
||||
<section class="section">
|
||||
<h3>{t('export')}</h3>
|
||||
<div class="row wrap">
|
||||
<button class="btn" onclick={() => download(`${fileBase()}-expenses.csv`, '' + expensesCsv(s.state), 'text/csv')}>{t('export_expenses')}</button>
|
||||
<button class="btn" onclick={() => download(`${fileBase()}-balances.csv`, '' + balancesCsv(s.state), 'text/csv')}>{t('export_balances')}</button>
|
||||
<button class="btn" onclick={backup}>{t('backup')}</button>
|
||||
<div class="row wrap exports">
|
||||
<button class="btn small" onclick={() => download(`${fileBase()}-expenses.csv`, '' + expensesCsv(s.state), 'text/csv')}>{t('export_expenses')}</button>
|
||||
<button class="btn small" onclick={() => download(`${fileBase()}-balances.csv`, '' + balancesCsv(s.state), 'text/csv')}>{t('export_balances')}</button>
|
||||
<button class="btn small" onclick={backup}>{t('backup')}</button>
|
||||
</div>
|
||||
<p class="small muted">{t('backup_hint')}</p>
|
||||
</section>
|
||||
|
|
@ -237,21 +245,63 @@
|
|||
<!-- danger -->
|
||||
<section class="section">
|
||||
<h3>{t('danger_zone')}</h3>
|
||||
<div class="card stack">
|
||||
<p class="small muted">{t('remove_from_device_hint')}</p>
|
||||
<button class="btn" onclick={removeFromDevice}>{t('remove_from_device')}</button>
|
||||
</div>
|
||||
<div class="card stack">
|
||||
<p class="small muted">{t('delete_group_hint')}</p>
|
||||
<input bind:value={deleteConfirm} placeholder={s.state.group?.name} aria-label={t('group_name')} />
|
||||
<button class="btn danger" disabled={deleteConfirm.trim() !== s.state.group?.name} onclick={deleteGroup}>
|
||||
<Icon name="trash" size={18} /> {t('delete_group')}
|
||||
<div class="list">
|
||||
<button class="item" onclick={removeFromDevice}>
|
||||
<Icon name="close" size={18} />
|
||||
<span class="grow">
|
||||
<span class="title" style:display="block">{t('remove_from_device')}</span>
|
||||
<span class="sub">{t('remove_from_device_hint')}</span>
|
||||
</span>
|
||||
</button>
|
||||
<button class="item danger" aria-expanded={deleteOpen} onclick={() => (deleteOpen = !deleteOpen)}>
|
||||
<Icon name="trash" size={18} />
|
||||
<span class="grow">
|
||||
<span class="title" style:display="block">{t('delete_group')}</span>
|
||||
<span class="sub">{t('delete_group_hint')}</span>
|
||||
</span>
|
||||
</button>
|
||||
{#if deleteOpen}
|
||||
<div class="confirm stack">
|
||||
<label class="field">
|
||||
{t('type_name_to_confirm')}
|
||||
<input bind:value={deleteConfirm} placeholder={s.state.group?.name} />
|
||||
</label>
|
||||
<button class="btn danger" disabled={deleteConfirm.trim() !== s.state.group?.name} onclick={deleteGroup}>
|
||||
<Icon name="trash" size={18} /> {t('delete_group')}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<style>
|
||||
.qr { width: min(260px, 100%); margin: 0 auto; background: #fff; border-radius: 12px; padding: 8px; }
|
||||
.qr { width: min(240px, 100%); margin: 0 auto; background: #fff; border-radius: 12px; padding: 8px; }
|
||||
.qr :global(svg) { width: 100%; height: auto; display: block; }
|
||||
.grow { flex: 1; }
|
||||
.btn.square { width: 48px; padding: 0; flex-shrink: 0; font-weight: 700; }
|
||||
.btn.square[aria-pressed='true'] { background: var(--surface-2); }
|
||||
.pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
|
||||
.item select.me { width: auto; max-width: 55%; min-height: 36px; padding: 4px 10px; }
|
||||
.item .icon-btn { width: 36px; height: 36px; color: var(--muted); }
|
||||
.item .icon-btn:disabled { opacity: 0.35; }
|
||||
.item.archived .title { color: var(--muted); }
|
||||
.item input.bare { border: 0; background: none; padding: 0; min-height: 36px; min-width: 0; flex: 1; }
|
||||
.item.danger, .item.danger .sub { color: var(--danger); }
|
||||
.item .sub { white-space: normal; }
|
||||
.exports .btn { flex: 1 1 auto; }
|
||||
.confirm { padding: 12px 14px 14px; }
|
||||
.switch {
|
||||
appearance: none; -webkit-appearance: none; flex-shrink: 0; cursor: pointer;
|
||||
width: 46px; height: 28px; min-height: 0; padding: 0; border-radius: 999px; position: relative;
|
||||
background: var(--surface-2); border: 1px solid var(--line); transition: background 0.15s;
|
||||
}
|
||||
.switch::after {
|
||||
content: ''; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px; border-radius: 50%;
|
||||
background: var(--text); transition: transform 0.15s;
|
||||
}
|
||||
.switch:checked { background: var(--accent); border-color: transparent; }
|
||||
.switch:checked::after { transform: translateX(18px); background: var(--accent-ink); }
|
||||
.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
|
||||
@media (prefers-reduced-motion: reduce) { .switch, .switch::after { transition: none; } }
|
||||
</style>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// Inline SVG icons (no icon font: keeps the CSP strict and works offline).
|
||||
const paths = {
|
||||
plus: 'M12 5v14M5 12h14',
|
||||
swap: 'M7 7h11l-3-3M17 17H6l3 3',
|
||||
back: 'M15 18l-6-6 6-6',
|
||||
close: 'M18 6L6 18M6 6l12 12',
|
||||
settings: 'M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1z',
|
||||
|
|
@ -19,6 +20,10 @@
|
|||
undo: 'M3 7v6h6M21 17a9 9 0 0 0-15-6.7L3 13',
|
||||
link: 'M10 13a5 5 0 0 0 7.5.5l3-3a5 5 0 0 0-7-7l-1.7 1.7M14 11a5 5 0 0 0-7.5-.5l-3 3a5 5 0 0 0 7 7l1.7-1.7',
|
||||
upload: 'M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4M17 8l-5-5-5 5M12 3v12',
|
||||
down: 'M6 9l6 6 6-6',
|
||||
up: 'M6 15l6-6 6 6',
|
||||
check: 'M20 6L9 17l-5-5',
|
||||
archive: 'M3 4h18v5H3zM5 9v11h14V9M10 13h4',
|
||||
} as const;
|
||||
|
||||
let { name, size = 22 }: { name: keyof typeof paths; size?: number } = $props();
|
||||
|
|
|
|||
10
apps/web/src/components/Money.svelte
Normal file
10
apps/web/src/components/Money.svelte
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<script lang="ts">
|
||||
// An amount with the whole number emphasised and the currency and
|
||||
// decimals de-emphasised. Reads the same as money() to screen readers.
|
||||
import { money, moneyParts } from '../lib/format.ts';
|
||||
|
||||
let { minor, currency, sign = false }: { minor: number; currency: string; sign?: boolean } = $props();
|
||||
const p = $derived(moneyParts(minor, currency, { sign }));
|
||||
</script>
|
||||
|
||||
<span class="money num"><span class="sr-only">{money(minor, currency, { sign })}</span><span aria-hidden="true"><span class="cur">{p.before}</span>{p.whole}<span class="frac">{p.frac}</span><span class="cur">{p.after}</span></span></span>
|
||||
|
|
@ -10,12 +10,17 @@
|
|||
|
||||
$effect(() => {
|
||||
dialog.showModal();
|
||||
// showModal() focuses the first control (the close button), which shows a
|
||||
// focus ring even after a tap. Focus the dialog itself instead, unless a
|
||||
// field asked for focus with autofocus. Tab still reaches every control.
|
||||
if (!dialog.querySelector('[autofocus]')) dialog.focus();
|
||||
return () => dialog.close();
|
||||
});
|
||||
</script>
|
||||
|
||||
<dialog
|
||||
class="sheet"
|
||||
tabindex="-1"
|
||||
bind:this={dialog}
|
||||
aria-label={title}
|
||||
oncancel={(e) => { e.preventDefault(); onclose(); }}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
</script>
|
||||
|
||||
<div class="stack">
|
||||
<div class="seg" role="group" aria-label={t('stats')}>
|
||||
<div class="seg compact" role="group" aria-label={t('stats')}>
|
||||
{#each [['all', 'range_all'], ['year', 'range_year'], ['month', 'range_month'], ['30', 'range_30']] as const as [r, label]}
|
||||
<button aria-pressed={range === r} onclick={() => (range = r)}>{t(label)}</button>
|
||||
{/each}
|
||||
|
|
@ -118,19 +118,20 @@
|
|||
</div>
|
||||
|
||||
<style>
|
||||
.seg.compact :global(button) { font-size: 0.84rem; padding: 0 6px; }
|
||||
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
|
||||
.hero { font-size: 1.6rem; font-weight: 700; }
|
||||
.s1 { background: var(--chart-1); }
|
||||
.s2 { background: var(--chart-2); }
|
||||
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
|
||||
.bars li { display: grid; grid-template-columns: minmax(90px, 34%) 1fr auto; align-items: center; gap: 10px; }
|
||||
.bars li { display: grid; grid-template-columns: minmax(90px, 34%) minmax(0, 1fr) auto; align-items: center; gap: 10px; }
|
||||
.label { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.track { display: block; height: 12px; }
|
||||
.hbar { display: block; height: 100%; min-width: 2px; border-radius: 0 4px 4px 0; }
|
||||
.value { font-size: 0.85rem; color: var(--text); text-align: right; }
|
||||
.grouped li { grid-template-columns: minmax(70px, 28%) 1fr; }
|
||||
.pair { display: flex; flex-direction: column; gap: 2px; }
|
||||
.line { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
|
||||
.line { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; align-items: center; }
|
||||
.legend { gap: 16px; }
|
||||
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
|
||||
.months { display: flex; align-items: stretch; gap: 2px; height: 160px; }
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ import { settings } from './settings.svelte.ts';
|
|||
|
||||
const cache = new Map<string, Intl.NumberFormat>();
|
||||
|
||||
/** Format minor units as money in the current locale ("1 234,50 Kč"). */
|
||||
export function money(minor: number, currency: string, opts: { sign?: boolean } = {}): string {
|
||||
function formatter(currency: string, opts: { sign?: boolean }): Intl.NumberFormat {
|
||||
const key = `${settings.locale}|${currency}|${opts.sign ? 1 : 0}`;
|
||||
let f = cache.get(key);
|
||||
if (!f) {
|
||||
|
|
@ -19,7 +18,30 @@ export function money(minor: number, currency: string, opts: { sign?: boolean }
|
|||
}
|
||||
cache.set(key, f);
|
||||
}
|
||||
return f.format(minor / 10 ** exponent(currency));
|
||||
return f;
|
||||
}
|
||||
|
||||
/** Format minor units as money in the current locale ("1 234,50 Kč"). */
|
||||
export function money(minor: number, currency: string, opts: { sign?: boolean } = {}): string {
|
||||
return formatter(currency, opts).format(minor / 10 ** exponent(currency));
|
||||
}
|
||||
|
||||
/**
|
||||
* The same text as money(), split so the whole number can be emphasised:
|
||||
* `before` (sign, currency), `whole` ("1 234"), `frac` (",50"), `after` (" Kč").
|
||||
*/
|
||||
export function moneyParts(minor: number, currency: string, opts: { sign?: boolean } = {}) {
|
||||
const out = { before: '', whole: '', frac: '', after: '' };
|
||||
let seenNumber = false;
|
||||
for (const p of formatter(currency, opts).formatToParts(minor / 10 ** exponent(currency))) {
|
||||
if (p.type === 'integer' || p.type === 'group') {
|
||||
out.whole += p.value;
|
||||
seenNumber = true;
|
||||
} else if (p.type === 'decimal' || p.type === 'fraction') out.frac += p.value;
|
||||
else if (seenNumber) out.after += p.value;
|
||||
else out.before += p.value;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Editable amount text for an input, in the user's decimal style. */
|
||||
|
|
@ -63,6 +85,13 @@ export function currencyName(code: string): string {
|
|||
}
|
||||
}
|
||||
|
||||
/** A hue per category, used to tint its round icon background. */
|
||||
export const CATEGORY_COLORS: Record<string, string> = {
|
||||
food: '#ff8f6b', groceries: '#3ddc97', transport: '#ffc85a', accommodation: '#7aa7ff', entertainment: '#e879a6',
|
||||
shopping: '#c084fc', utilities: '#facc15', rent: '#4fd1c5', travel: '#60a5fa', gifts: '#f472b6', health: '#f87171',
|
||||
other: '#9ca3af', transfer: '#3ddc97',
|
||||
};
|
||||
|
||||
export const CATEGORY_ICONS: Record<string, string> = {
|
||||
food: '🍽️', groceries: '🛒', transport: '🚕', accommodation: '🏨', entertainment: '🎟️',
|
||||
shopping: '🛍️', utilities: '💡', rent: '🏠', travel: '✈️', gifts: '🎁', health: '💊',
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ const cs: Messages = {
|
|||
creating: 'Vytvářím…',
|
||||
|
||||
share_group: 'Sdílet skupinu',
|
||||
share_intro: 'Kdokoli s tímto odkazem může skupinu vidět i upravovat. Posílejte ho jen členům.',
|
||||
share_intro: 'Kdo má odkaz, může skupinu vidět i upravovat.',
|
||||
save_link_warning: 'Uložte si tento odkaz na bezpečné místo. Pokud se ztratí všechny kopie, skupinu nepůjde obnovit.',
|
||||
copy_link: 'Kopírovat odkaz',
|
||||
copied: 'Zkopírováno',
|
||||
|
|
@ -62,10 +62,21 @@ const cs: Messages = {
|
|||
stats: 'Statistiky',
|
||||
activity: 'Aktivita',
|
||||
add_expense: 'Přidat výdaj',
|
||||
pull_to_add: 'Táhněte nahoru pro nový výdaj',
|
||||
release_to_add: 'Pusťte a přidejte',
|
||||
no_expenses: 'Zatím žádné výdaje. Klepněte na + a přidejte první.',
|
||||
total_spent: 'Celkem utraceno',
|
||||
summary: 'Přehled',
|
||||
hero_owed: 'Dluží vám',
|
||||
hero_owe: 'Dlužíte',
|
||||
hero_settled: 'Máte vyrovnáno',
|
||||
quick_actions: 'Rychlé akce',
|
||||
add: 'Přidat',
|
||||
share_short: 'Sdílet',
|
||||
payment_short: 'Platba',
|
||||
add_payment: 'Zaznamenat platbu',
|
||||
paid_by: 'Platil(a) {name}',
|
||||
paid_by_many: 'Platilo {n} lidí',
|
||||
paid_by_many: { one: '{n} plátce', few: '{n} plátci', other: '{n} plátců' },
|
||||
your_share: 'váš podíl {amount}',
|
||||
you_lent: 'půjčili jste {amount}',
|
||||
you_borrowed: 'dlužíte {amount}',
|
||||
|
|
@ -97,6 +108,7 @@ const cs: Messages = {
|
|||
title: 'Za co?',
|
||||
title_ph: 'Večeře',
|
||||
category: 'Kategorie',
|
||||
default_category: 'Výchozí kategorie',
|
||||
date: 'Datum',
|
||||
currency: 'Měna',
|
||||
rate: 'Směnný kurz',
|
||||
|
|
@ -107,7 +119,7 @@ const cs: Messages = {
|
|||
currencies_manual: 'Kurz zadáte ručně',
|
||||
rate_unavailable: 'Pro tuto měnu není kurz k dispozici, zadejte ho prosím.',
|
||||
paid_by_label: 'Platil(a)',
|
||||
multiple_payers: 'Platilo více lidí',
|
||||
multiple_payers: 'Více lidí',
|
||||
from_label: 'Od',
|
||||
to_label: 'Komu',
|
||||
split: 'Rozdělení',
|
||||
|
|
@ -117,11 +129,11 @@ const cs: Messages = {
|
|||
split_percent: 'Procenta',
|
||||
remaining: 'Zbývá: {amount}',
|
||||
over_by: 'Přebývá: {amount}',
|
||||
adds_up: 'Součet sedí',
|
||||
select_all: 'Všichni',
|
||||
select_none: 'Nikdo',
|
||||
note: 'Poznámka',
|
||||
photo: 'Fotka',
|
||||
add_photo: 'Přidat fotku',
|
||||
replace_photo: 'Vyměnit',
|
||||
remove_photo: 'Odebrat',
|
||||
processing_photo: 'Zpracovávám fotku…',
|
||||
|
|
@ -179,10 +191,10 @@ const cs: Messages = {
|
|||
changed_fields: 'Změněno: {fields}',
|
||||
no_activity: 'Zatím žádná aktivita.',
|
||||
|
||||
range_all: 'Celé období',
|
||||
range_all: 'Vše',
|
||||
range_month: 'Tento měsíc',
|
||||
range_30: 'Posledních 30 dní',
|
||||
range_year: 'Tento rok',
|
||||
range_30: '30 dní',
|
||||
range_year: 'Letos',
|
||||
by_category: 'Podle kategorie',
|
||||
by_month: 'Podle měsíce',
|
||||
per_member: 'Zaplaceno vs. podíl',
|
||||
|
|
@ -202,7 +214,7 @@ const cs: Messages = {
|
|||
not_set: 'Nenastaveno',
|
||||
change: 'Změnit',
|
||||
notifications: 'Oznámení',
|
||||
notifications_hint: 'Dostanete oznámení, když skupinu změní někdo jiný.',
|
||||
notifications_hint: 'Upozornit mě, když skupinu změní ostatní',
|
||||
notifications_ios: 'Na iPhonu a iPadu nejdřív přidejte OweMe na plochu (Sdílet → Přidat na plochu).',
|
||||
notifications_denied: 'Oznámení jsou pro tento web zablokovaná v nastavení prohlížeče.',
|
||||
notifications_unavailable: 'Oznámení nejsou na tomto serveru nebo v tomto prohlížeči k dispozici.',
|
||||
|
|
@ -214,11 +226,14 @@ const cs: Messages = {
|
|||
export_expenses: 'Výdaje (CSV)',
|
||||
export_balances: 'Zůstatky (CSV)',
|
||||
backup: 'Soubor se zálohou',
|
||||
backup_hint: 'Obsahuje klíč skupiny: kdokoli se souborem skupinu otevře. Uložte ho bezpečně.',
|
||||
backup_hint: 'Záloha obsahuje klíč skupiny. Uložte ji bezpečně.',
|
||||
danger_zone: 'Nebezpečná zóna',
|
||||
remove_from_device_hint: 'Skupina zůstane na serveru i v ostatních zařízeních.',
|
||||
remove_from_device_hint: 'Zůstane na serveru i v ostatních zařízeních.',
|
||||
delete_group: 'Smazat skupinu pro všechny',
|
||||
delete_group_hint: 'Smaže ze serveru všechny výdaje a fotky. Pro potvrzení napište název skupiny.',
|
||||
delete_group_hint: 'Všem smaže všechny výdaje a fotky.',
|
||||
type_name_to_confirm: 'Pro potvrzení napište název skupiny',
|
||||
qr_code: 'QR kód',
|
||||
group: 'Skupina',
|
||||
confirm: 'Potvrdit',
|
||||
saved: 'Uloženo',
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ const en = {
|
|||
|
||||
// share
|
||||
share_group: 'Share group',
|
||||
share_intro: 'Anyone with this link can see and edit the group. Send it only to group members.',
|
||||
share_intro: 'Anyone with the link can view and edit this group.',
|
||||
save_link_warning: 'Save this link somewhere safe. If every copy is lost, the group can’t be recovered.',
|
||||
copy_link: 'Copy link',
|
||||
copied: 'Copied',
|
||||
|
|
@ -68,10 +68,21 @@ const en = {
|
|||
stats: 'Stats',
|
||||
activity: 'Activity',
|
||||
add_expense: 'Add expense',
|
||||
pull_to_add: 'Pull up to add expense',
|
||||
release_to_add: 'Release to add',
|
||||
no_expenses: 'No expenses yet. Tap + to add the first one.',
|
||||
total_spent: 'Total spent',
|
||||
summary: 'Summary',
|
||||
hero_owed: 'You’re owed',
|
||||
hero_owe: 'You owe',
|
||||
hero_settled: 'You’re settled up',
|
||||
quick_actions: 'Quick actions',
|
||||
add: 'Add',
|
||||
share_short: 'Share',
|
||||
payment_short: 'Payment',
|
||||
add_payment: 'Record a payment',
|
||||
paid_by: 'Paid by {name}',
|
||||
paid_by_many: 'Paid by {n} people',
|
||||
paid_by_many: { one: '{n} payer', few: '{n} payers', other: '{n} payers' },
|
||||
your_share: 'your share {amount}',
|
||||
you_lent: 'you lent {amount}',
|
||||
you_borrowed: 'you borrowed {amount}',
|
||||
|
|
@ -105,6 +116,7 @@ const en = {
|
|||
title: 'What was it for?',
|
||||
title_ph: 'Dinner',
|
||||
category: 'Category',
|
||||
default_category: 'Default category',
|
||||
date: 'Date',
|
||||
currency: 'Currency',
|
||||
rate: 'Exchange rate',
|
||||
|
|
@ -115,7 +127,7 @@ const en = {
|
|||
currencies_manual: 'Enter rate manually',
|
||||
rate_unavailable: 'No rate available for this currency, please enter it.',
|
||||
paid_by_label: 'Paid by',
|
||||
multiple_payers: 'Several people paid',
|
||||
multiple_payers: 'Several people',
|
||||
from_label: 'From',
|
||||
to_label: 'To',
|
||||
split: 'Split',
|
||||
|
|
@ -125,11 +137,11 @@ const en = {
|
|||
split_percent: 'Percent',
|
||||
remaining: 'Remaining: {amount}',
|
||||
over_by: 'Over by: {amount}',
|
||||
adds_up: 'Adds up to the total',
|
||||
select_all: 'All',
|
||||
select_none: 'None',
|
||||
note: 'Note',
|
||||
photo: 'Photo',
|
||||
add_photo: 'Add photo',
|
||||
replace_photo: 'Replace',
|
||||
remove_photo: 'Remove',
|
||||
processing_photo: 'Processing photo…',
|
||||
|
|
@ -190,9 +202,9 @@ const en = {
|
|||
no_activity: 'No activity yet.',
|
||||
|
||||
// stats
|
||||
range_all: 'All time',
|
||||
range_all: 'All',
|
||||
range_month: 'This month',
|
||||
range_30: 'Last 30 days',
|
||||
range_30: '30 days',
|
||||
range_year: 'This year',
|
||||
by_category: 'By category',
|
||||
by_month: 'By month',
|
||||
|
|
@ -214,7 +226,7 @@ const en = {
|
|||
not_set: 'Not set',
|
||||
change: 'Change',
|
||||
notifications: 'Notifications',
|
||||
notifications_hint: 'Get a notification when someone else changes this group.',
|
||||
notifications_hint: 'Notify me when others change the group',
|
||||
notifications_ios: 'On iPhone and iPad, add OweMe to your home screen first (Share → Add to Home Screen).',
|
||||
notifications_denied: 'Notifications are blocked for this site in your browser settings.',
|
||||
notifications_unavailable: 'Notifications aren’t available on this server or in this browser.',
|
||||
|
|
@ -226,11 +238,14 @@ const en = {
|
|||
export_expenses: 'Expenses (CSV)',
|
||||
export_balances: 'Balances (CSV)',
|
||||
backup: 'Backup file',
|
||||
backup_hint: 'Contains the group key: anyone with the file can open the group. Store it safely.',
|
||||
backup_hint: 'The backup file contains the group key. Store it safely.',
|
||||
danger_zone: 'Danger zone',
|
||||
remove_from_device_hint: 'The group stays on the server and on other devices.',
|
||||
remove_from_device_hint: 'Stays on the server and other devices.',
|
||||
delete_group: 'Delete group for everyone',
|
||||
delete_group_hint: 'Deletes all expenses and photos from the server. Type the group name to confirm.',
|
||||
delete_group_hint: 'Removes all expenses and photos for everyone.',
|
||||
type_name_to_confirm: 'Type the group name to confirm',
|
||||
qr_code: 'QR code',
|
||||
group: 'Group',
|
||||
confirm: 'Confirm',
|
||||
saved: 'Saved',
|
||||
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ test('two devices share a group end to end', async ({ browser }) => {
|
|||
const fmt = (minor: number) => (minor / 100).toLocaleString('en-US', { minimumFractionDigits: 2 });
|
||||
const shown = `${annaBal > 0 ? '+' : '−'}CZK ${fmt(Math.abs(annaBal))}`;
|
||||
await expect(anna.getByText(shown).first()).toBeVisible();
|
||||
await expect(anna.getByText('Settle up')).toBeVisible();
|
||||
await expect(anna.getByRole('heading', { name: 'Settle up' })).toBeVisible();
|
||||
const recordButtons = anna.getByRole('button', { name: 'Record payment' });
|
||||
const transfers = await recordButtons.count();
|
||||
expect(transfers).toBeGreaterThan(0);
|
||||
|
|
@ -143,3 +143,40 @@ test('two devices share a group end to end', async ({ browser }) => {
|
|||
await expect(anna.getByRole('heading', { name: 'By category' })).toBeVisible();
|
||||
await expect(anna.getByRole('heading', { name: 'Paid vs. share' })).toBeVisible();
|
||||
});
|
||||
|
||||
test('several people pay for one expense', async ({ browser }) => {
|
||||
const p = await device(browser, 'en-US');
|
||||
await p.goto('/');
|
||||
await p.getByRole('link', { name: 'New group' }).click();
|
||||
await p.getByLabel('Group name').fill('Shared car');
|
||||
await p.getByLabel('Main currency').selectOption('CZK');
|
||||
await p.getByLabel('Your name').fill('Anna');
|
||||
await p.getByPlaceholder('Name').fill('Petr');
|
||||
await p.getByRole('button', { name: 'Add member' }).click();
|
||||
await p.getByPlaceholder('Name').nth(1).fill('Jana');
|
||||
await p.getByRole('button', { name: 'Create group' }).click();
|
||||
await p.getByRole('button', { name: 'Back', exact: true }).click();
|
||||
|
||||
await p.getByRole('link', { name: 'Add expense' }).click();
|
||||
await p.getByLabel('Amount').fill('300000');
|
||||
await p.getByLabel('What was it for?').fill('Car');
|
||||
await p.getByLabel('Paid by', { exact: true }).selectOption({ label: 'Several people' });
|
||||
await p.getByLabel('Paid by: Anna').fill('100000');
|
||||
await p.getByLabel('Paid by: Petr').fill('150000');
|
||||
await expect(p.getByText('Remaining: CZK 50,000.00')).toBeVisible();
|
||||
// The empty box suggests what's left.
|
||||
await expect(p.getByLabel('Paid by: Jana')).toHaveAttribute('placeholder', '50000.00');
|
||||
await p.getByLabel('Paid by: Jana').fill('80000');
|
||||
await expect(p.getByText('Over by: CZK 30,000.00')).toBeVisible();
|
||||
await p.getByRole('button', { name: 'Save', exact: true }).click();
|
||||
await expect(p.getByRole('alert')).toHaveText('The payers don’t add up to the amount.');
|
||||
await p.getByLabel('Paid by: Jana').fill('50000');
|
||||
await expect(p.getByText('Adds up to the total')).toBeVisible();
|
||||
await p.getByRole('button', { name: 'Save', exact: true }).click();
|
||||
|
||||
await expect(p.getByRole('link', { name: /Car/ })).toContainText('3 payers');
|
||||
await p.getByRole('link', { name: 'Balances' }).click();
|
||||
await expect(p.getByText('+CZK 50,000.00')).toBeVisible();
|
||||
await expect(p.getByText('−CZK 50,000.00')).toBeVisible();
|
||||
await expect(p.getByText('Jana → Petr')).toBeVisible();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
// after its target event; nothing is ever erased from the log. See SPEC.md §6.
|
||||
import { validateExpense } from './expense.ts';
|
||||
import { isCurrencyCode } from './money.ts';
|
||||
import type { Activity, GroupEvent, GroupState, Recurring } from './types.ts';
|
||||
import { CATEGORIES, type Activity, type GroupEvent, type GroupState, type Recurring } from './types.ts';
|
||||
|
||||
const isCategory = (c: unknown): c is (typeof CATEGORIES)[number] => (CATEGORIES as readonly unknown[]).includes(c);
|
||||
|
||||
export function emptyState(): GroupState {
|
||||
return { group: null, members: [], expenses: {}, comments: {}, recurring: {} };
|
||||
|
|
@ -40,18 +42,22 @@ function apply(s: GroupState, ev: GroupEvent, snapshots: Map<string, GroupState>
|
|||
const d = ev.data;
|
||||
if (s.group || !str(d?.name, 100) || !isCurrencyCode(d.baseCurrency)) return ignore();
|
||||
s.group = { name: d.name, baseCurrency: d.baseCurrency, icon: typeof d.icon === 'string' ? d.icon.slice(0, 16) : '' };
|
||||
if (isCategory(d.defaultCategory)) s.group.defaultCategory = d.defaultCategory;
|
||||
act.after = { ...s.group };
|
||||
break;
|
||||
}
|
||||
case 'group.updated': {
|
||||
if (!s.group) return ignore();
|
||||
const d = ev.data ?? {};
|
||||
// Validate before changing anything, so an invalid event has no effect.
|
||||
if (d.defaultCategory !== undefined && !isCategory(d.defaultCategory)) return ignore();
|
||||
act.before = { ...s.group };
|
||||
if (d.name !== undefined) {
|
||||
if (!str(d.name, 100)) return ignore();
|
||||
s.group.name = d.name;
|
||||
}
|
||||
if (typeof d.icon === 'string') s.group.icon = d.icon.slice(0, 16);
|
||||
if (d.defaultCategory !== undefined) s.group.defaultCategory = d.defaultCategory;
|
||||
if (d.baseCurrency !== undefined && d.baseCurrency !== s.group.baseCurrency) {
|
||||
// Locked once the group has any expense (SPEC §7.1).
|
||||
if (hasExpenses || !isCurrencyCode(d.baseCurrency)) return ignore();
|
||||
|
|
|
|||
|
|
@ -81,6 +81,8 @@ export interface GroupInfo {
|
|||
name: string;
|
||||
baseCurrency: string;
|
||||
icon: string;
|
||||
/** category new expenses start with; absent = 'other' */
|
||||
defaultCategory?: (typeof CATEGORIES)[number];
|
||||
}
|
||||
|
||||
export type EventBody =
|
||||
|
|
|
|||
|
|
@ -110,6 +110,31 @@ describe('replay', () => {
|
|||
expect(Object.values(bal).reduce((x, y) => x + y)).toBe(0);
|
||||
});
|
||||
|
||||
it('credits each of several payers (three people buy a car together)', () => {
|
||||
const car = expense({
|
||||
amount: 30000000,
|
||||
payers: [{ member: 'a', amount: 10000000 }, { member: 'b', amount: 15000000 }, { member: 'c', amount: 5000000 }],
|
||||
});
|
||||
const { state } = replay([...baseGroup(), ev({ type: 'expense.created', data: car })]);
|
||||
const bal = balances(state);
|
||||
expect(bal).toEqual({ a: 0, b: 5000000, c: -5000000 });
|
||||
expect(settleUp(bal, ['a', 'b', 'c'])).toEqual([{ from: 'c', to: 'b', amount: 5000000 }]);
|
||||
});
|
||||
|
||||
it('credits several payers in a foreign currency, summing exactly to the base total', () => {
|
||||
// €100.01 at 25.1 = 2510.251 Kč → 2510.25; payer and share vectors must each sum to it.
|
||||
const e = expense({
|
||||
currency: 'EUR', amount: 10001, rate: '25.1',
|
||||
payers: [{ member: 'a', amount: 5001 }, { member: 'b', amount: 5000 }],
|
||||
});
|
||||
const { state } = replay([...baseGroup(), ev({ type: 'expense.created', data: e })]);
|
||||
const bal = balances(state);
|
||||
expect(Object.values(bal).reduce((x, y) => x + y)).toBe(0);
|
||||
expect(bal.a).toBeGreaterThan(0);
|
||||
expect(bal.b).toBeGreaterThan(0);
|
||||
expect(bal.c).toBeLessThan(0);
|
||||
});
|
||||
|
||||
it('ignores invalid expenses (bad sums, unknown members)', () => {
|
||||
const bad1 = expense({ id: 'x2', payers: [{ member: 'a', amount: 1 }] });
|
||||
const bad2 = expense({ id: 'x3', split: { mode: 'equal', entries: [{ member: 'zzz', value: 1 }] } });
|
||||
|
|
@ -149,6 +174,15 @@ describe('replay', () => {
|
|||
expect(replay(locked).state.group!.baseCurrency).toBe('CZK');
|
||||
});
|
||||
|
||||
it('sets a default category and ignores invalid ones', () => {
|
||||
const set = [...baseGroup(), ev({ type: 'group.updated', data: { defaultCategory: 'travel' } })];
|
||||
expect(replay(set).state.group!.defaultCategory).toBe('travel');
|
||||
const bad = [...set, ev({ type: 'group.updated', data: { defaultCategory: 'transfer' as never, name: 'Renamed' } })];
|
||||
const g = replay(bad).state.group!;
|
||||
expect(g.defaultCategory).toBe('travel');
|
||||
expect(g.name).not.toBe('Renamed'); // the whole invalid event is ignored
|
||||
});
|
||||
|
||||
it('revert restores an earlier state, and can itself be reverted', () => {
|
||||
const evs = [...baseGroup(), ev({ type: 'expense.created', data: expense() }, 'a', 'keep')];
|
||||
evs.push(ev({ type: 'expense.updated', data: expense({ amount: 99900, payers: [{ member: 'a', amount: 99900 }] }) }, 'b', 'vandal'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue