Pull down to add an expense
On touch screens, dragging the Expenses or Balances tab down from the top slides a "Pull to add expense" pill out from under the header; releasing once it reads "Release to add" opens the add sheet. Sideways swipes, upward scrolls and touches on form controls are left alone, and the browser's pull-to-refresh is suppressed only while a pull is in progress. The visible Add buttons stay; the pill is aria-hidden. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HA82gVKYyo9BHLHPW4qr4x
This commit is contained in:
parent
a10ec3c3b3
commit
ce1b207906
5 changed files with 137 additions and 0 deletions
4
SPEC.md
4
SPEC.md
|
|
@ -283,6 +283,10 @@ the minimum in practice, and is easy to reason about.
|
||||||
one row of 12 when wider) with the chosen name beside the label; date and
|
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
|
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.
|
and repeat stay folded behind small buttons; Save is pinned to the bottom.
|
||||||
|
- Pull to add: on a touch screen, dragging the Expenses or Balances tab down
|
||||||
|
from the very top shows a "Pull to add expense" pill under the header;
|
||||||
|
releasing once it reads "Release to add" opens the add sheet. It replaces
|
||||||
|
the browser's pull-to-refresh there (sync is live anyway).
|
||||||
- **One photo per expense** (receipt), see 9.
|
- **One photo per expense** (receipt), see 9.
|
||||||
- Category, date, note.
|
- Category, date, note.
|
||||||
- Comments thread on each expense.
|
- Comments thread on each expense.
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
import GroupSettings from './GroupSettings.svelte';
|
import GroupSettings from './GroupSettings.svelte';
|
||||||
import Icon from './Icon.svelte';
|
import Icon from './Icon.svelte';
|
||||||
import IdentityPicker from './IdentityPicker.svelte';
|
import IdentityPicker from './IdentityPicker.svelte';
|
||||||
|
import PullToAdd from './PullToAdd.svelte';
|
||||||
import Stats from './Stats.svelte';
|
import Stats from './Stats.svelte';
|
||||||
|
|
||||||
// Keyed by group id in App.svelte, so reading it once is enough.
|
// Keyed by group id in App.svelte, so reading it once is enough.
|
||||||
|
|
@ -121,6 +122,11 @@
|
||||||
<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>
|
<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}
|
||||||
|
|
||||||
|
<PullToAdd
|
||||||
|
enabled={route.name === 'group' && withHeader && s.status !== 'gone' && !needsIdentity}
|
||||||
|
onadd={() => router.go(`${base}/e/new`)}
|
||||||
|
/>
|
||||||
|
|
||||||
{#if route.name === 'expense'}
|
{#if route.name === 'expense'}
|
||||||
<ExpenseDetail session={s} eid={route.eid} />
|
<ExpenseDetail session={s} eid={route.eid} />
|
||||||
{:else if route.name === 'expense-edit'}
|
{:else if route.name === 'expense-edit'}
|
||||||
|
|
|
||||||
123
apps/web/src/components/PullToAdd.svelte
Normal file
123
apps/web/src/components/PullToAdd.svelte
Normal file
|
|
@ -0,0 +1,123 @@
|
||||||
|
<script lang="ts">
|
||||||
|
// Pull-down-to-add: on a touch screen, dragging the page down from the very
|
||||||
|
// top slides a pill out from under the header; letting go once it reads
|
||||||
|
// "Release to add" opens the add-expense sheet. The visible Add buttons stay,
|
||||||
|
// so this is a shortcut, not the only way in (the pill is aria-hidden).
|
||||||
|
import { t } from '../lib/settings.svelte.ts';
|
||||||
|
import Icon from './Icon.svelte';
|
||||||
|
|
||||||
|
const { enabled, onadd }: { enabled: boolean; onadd: () => void } = $props();
|
||||||
|
|
||||||
|
/** How far the pill must travel (after resistance) before a release adds. */
|
||||||
|
const THRESHOLD = 72;
|
||||||
|
const MAX = 110;
|
||||||
|
/** Finger movement before we decide whether this is a vertical pull. */
|
||||||
|
const SLOP = 8;
|
||||||
|
|
||||||
|
let pull = $state(0);
|
||||||
|
let top = $state(0);
|
||||||
|
let releasing = $state(false);
|
||||||
|
const armed = $derived(pull >= THRESHOLD);
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
if (!enabled) return;
|
||||||
|
// Tracking state for one touch; null = not a candidate for a pull.
|
||||||
|
let start: { x: number; y: number } | null = null;
|
||||||
|
let pulling = false;
|
||||||
|
let wasArmed = false;
|
||||||
|
|
||||||
|
const reset = () => {
|
||||||
|
start = null;
|
||||||
|
pulling = false;
|
||||||
|
wasArmed = false;
|
||||||
|
releasing = true;
|
||||||
|
pull = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStart = (e: TouchEvent) => {
|
||||||
|
start = null;
|
||||||
|
if (e.touches.length !== 1 || window.scrollY > 0) return;
|
||||||
|
// Leave form controls (search box, selects) to do their own thing.
|
||||||
|
if ((e.target as Element | null)?.closest('input, textarea, select, dialog')) return;
|
||||||
|
const tch = e.touches[0];
|
||||||
|
start = { x: tch.clientX, y: tch.clientY };
|
||||||
|
top = document.querySelector('.topbar')?.getBoundingClientRect().bottom ?? 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMove = (e: TouchEvent) => {
|
||||||
|
if (!start) return;
|
||||||
|
const tch = e.touches[0];
|
||||||
|
const dx = tch.clientX - start.x;
|
||||||
|
const dy = tch.clientY - start.y;
|
||||||
|
if (!pulling) {
|
||||||
|
if (Math.abs(dx) < SLOP && Math.abs(dy) < SLOP) return;
|
||||||
|
// Sideways swipes and upward scrolls aren't ours.
|
||||||
|
if (dy <= 0 || Math.abs(dx) > Math.abs(dy) || window.scrollY > 0) {
|
||||||
|
start = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pulling = true;
|
||||||
|
releasing = false;
|
||||||
|
}
|
||||||
|
// Stop the browser's own pull-to-refresh / rubber band while we pull.
|
||||||
|
if (e.cancelable) e.preventDefault();
|
||||||
|
pull = Math.min(MAX, Math.max(0, dy - SLOP) * 0.55);
|
||||||
|
const nowArmed = pull >= THRESHOLD;
|
||||||
|
if (nowArmed && !wasArmed) navigator.vibrate?.(10);
|
||||||
|
wasArmed = nowArmed;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onEnd = () => {
|
||||||
|
if (!start) return;
|
||||||
|
const add = pulling && pull >= THRESHOLD;
|
||||||
|
reset();
|
||||||
|
if (add) onadd();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener('touchstart', onStart, { passive: true });
|
||||||
|
window.addEventListener('touchmove', onMove, { passive: false });
|
||||||
|
window.addEventListener('touchend', onEnd);
|
||||||
|
window.addEventListener('touchcancel', reset);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('touchstart', onStart);
|
||||||
|
window.removeEventListener('touchmove', onMove);
|
||||||
|
window.removeEventListener('touchend', onEnd);
|
||||||
|
window.removeEventListener('touchcancel', reset);
|
||||||
|
pull = 0;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class="pull"
|
||||||
|
class:armed
|
||||||
|
class:releasing
|
||||||
|
aria-hidden="true"
|
||||||
|
style:top="{top}px"
|
||||||
|
style:transform="translate(-50%, {pull - 48}px)"
|
||||||
|
style:opacity={Math.min(1, pull / 32)}
|
||||||
|
>
|
||||||
|
<span class="c"><Icon name={armed ? 'plus' : 'down'} 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>
|
||||||
|
|
@ -62,6 +62,8 @@ const cs: Messages = {
|
||||||
stats: 'Statistiky',
|
stats: 'Statistiky',
|
||||||
activity: 'Aktivita',
|
activity: 'Aktivita',
|
||||||
add_expense: 'Přidat výdaj',
|
add_expense: 'Přidat výdaj',
|
||||||
|
pull_to_add: 'Táhněte dolů 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í.',
|
no_expenses: 'Zatím žádné výdaje. Klepněte na + a přidejte první.',
|
||||||
total_spent: 'Celkem utraceno',
|
total_spent: 'Celkem utraceno',
|
||||||
summary: 'Přehled',
|
summary: 'Přehled',
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,8 @@ const en = {
|
||||||
stats: 'Stats',
|
stats: 'Stats',
|
||||||
activity: 'Activity',
|
activity: 'Activity',
|
||||||
add_expense: 'Add expense',
|
add_expense: 'Add expense',
|
||||||
|
pull_to_add: 'Pull to add expense',
|
||||||
|
release_to_add: 'Release to add',
|
||||||
no_expenses: 'No expenses yet. Tap + to add the first one.',
|
no_expenses: 'No expenses yet. Tap + to add the first one.',
|
||||||
total_spent: 'Total spent',
|
total_spent: 'Total spent',
|
||||||
summary: 'Summary',
|
summary: 'Summary',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue