Add Svelte web client and service worker
Mobile-first PWA: groups via key-in-fragment links, encrypted outbox and sync over SSE, all split modes, currencies with ECB rate prefill, photos, comments, history and rewind, stats, recurring expenses, CSV and backup, EN/CS, dark/light theme, Web Push decrypted in the service worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
This commit is contained in:
parent
f67add3660
commit
8fbbb4933e
53 changed files with 4558 additions and 37 deletions
132
apps/web/src/components/GroupPage.svelte
Normal file
132
apps/web/src/components/GroupPage.svelte
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
<script lang="ts">
|
||||
import { onDestroy, 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';
|
||||
import { t } from '../lib/settings.svelte.ts';
|
||||
import Activity from './Activity.svelte';
|
||||
import Balances from './Balances.svelte';
|
||||
import ExpenseDetail from './ExpenseDetail.svelte';
|
||||
import ExpenseEditor from './ExpenseEditor.svelte';
|
||||
import ExpenseList from './ExpenseList.svelte';
|
||||
import GroupSettings from './GroupSettings.svelte';
|
||||
import Icon from './Icon.svelte';
|
||||
import IdentityPicker from './IdentityPicker.svelte';
|
||||
import Stats from './Stats.svelte';
|
||||
|
||||
// Keyed by group id in App.svelte, so reading it once is enough.
|
||||
const props: { id: string } = $props();
|
||||
const id = untrack(() => props.id);
|
||||
let session = $state<GroupSession | null | undefined>(undefined);
|
||||
let skippedIdentity = $state(false);
|
||||
|
||||
openSession(id).then((s) => (session = s));
|
||||
onDestroy(() => closeSession(id));
|
||||
|
||||
const route = $derived(router.route);
|
||||
const tab = $derived(route.name === 'group' ? route.tab : 'expenses');
|
||||
const base = `/g/${id}`;
|
||||
const tabs = [
|
||||
{ key: 'expenses', path: base, icon: 'list', label: 'expenses' },
|
||||
{ key: 'balances', path: `${base}/balances`, icon: 'scale', label: 'balances' },
|
||||
{ key: 'stats', path: `${base}/stats`, icon: 'chart', label: 'stats' },
|
||||
{ key: 'activity', path: `${base}/activity`, icon: 'clock', label: 'activity' },
|
||||
] as const;
|
||||
|
||||
function nav(e: MouseEvent, path: string, replace = false) {
|
||||
e.preventDefault();
|
||||
router.go(path, { replace });
|
||||
}
|
||||
|
||||
const needsIdentity = $derived(
|
||||
!!session && session.status !== 'loading' && session.state.members.length > 0 && !session.me && !skippedIdentity,
|
||||
);
|
||||
|
||||
async function remove() {
|
||||
await forgetGroup(id);
|
||||
router.go('/', { replace: true });
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if session === undefined}
|
||||
<main class="page"><p class="empty">{t('loading')}</p></main>
|
||||
{:else if session === null}
|
||||
<header class="topbar">
|
||||
<button class="icon-btn" onclick={() => router.go('/')} aria-label={t('back')}><Icon name="back" /></button>
|
||||
<h1>{t('app_name')}</h1>
|
||||
</header>
|
||||
<main class="page"><p class="card">{t('group_not_on_device')}</p></main>
|
||||
{:else if route.name === 'group-settings'}
|
||||
<GroupSettings {session} />
|
||||
{:else}
|
||||
{@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>
|
||||
<a class="icon-btn" href="{base}/settings" onclick={(e) => nav(e, `${base}/settings`)} aria-label={t('group_settings')}><Icon name="settings" /></a>
|
||||
</header>
|
||||
|
||||
<main class="page wide stack">
|
||||
{#if s.status === 'gone'}
|
||||
<div class="banner danger stack">
|
||||
<p>{t('not_found_group')}</p>
|
||||
<button class="btn small danger" onclick={remove}>{t('remove_from_device')}</button>
|
||||
</div>
|
||||
{:else if s.status === 'offline'}
|
||||
<p class="banner">{t('offline')}</p>
|
||||
{/if}
|
||||
{#if s.pending.length && s.status !== 'online'}
|
||||
<p class="muted small">{t('pending', { n: s.pending.length })}</p>
|
||||
{/if}
|
||||
{#if s.rollback}<p class="banner warn">{t('rollback_warning')}</p>{/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)}>
|
||||
<Icon name={tb.icon} size={20} />
|
||||
{t(tb.label)}
|
||||
</a>
|
||||
{/each}
|
||||
</nav>
|
||||
|
||||
<div class="layout" class:with-side={tab === 'expenses'}>
|
||||
<div class="main-col">
|
||||
{#if tab === 'expenses'}
|
||||
<ExpenseList session={s} />
|
||||
{:else if tab === 'balances'}
|
||||
<Balances session={s} />
|
||||
{:else if tab === 'stats'}
|
||||
<Stats session={s} />
|
||||
{:else}
|
||||
<Activity session={s} />
|
||||
{/if}
|
||||
</div>
|
||||
{#if tab === 'expenses'}
|
||||
<aside class="side-col"><Balances session={s} compact /></aside>
|
||||
{/if}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
{#if s.status !== 'gone' && (tab === 'expenses' || tab === 'balances')}
|
||||
<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}
|
||||
|
||||
{#if route.name === 'expense'}
|
||||
<ExpenseDetail session={s} eid={route.eid} />
|
||||
{:else if route.name === 'expense-edit'}
|
||||
{#key route.eid}
|
||||
<ExpenseEditor session={s} eid={route.eid} params={route.params} />
|
||||
{/key}
|
||||
{:else if needsIdentity}
|
||||
<IdentityPicker session={s} onskip={() => (skippedIdentity = true)} />
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.layout { display: grid; gap: 24px; }
|
||||
.side-col { display: none; }
|
||||
@media (min-width: 960px) {
|
||||
.layout.with-side { grid-template-columns: minmax(0, 1fr) 340px; }
|
||||
.side-col { display: block; position: sticky; top: 80px; align-self: start; }
|
||||
}
|
||||
</style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue