Redesign calendar screen
This commit is contained in:
1 parent
569f125f7d
commit
59be6b6ecf
1 file changed
+122
-63
@@ -1,7 +1,21 @@
|
||||
<script lang="ts">
|
||||
import CalendarDays from '@lucide/svelte/icons/calendar-days';
|
||||
import CalendarPlus from '@lucide/svelte/icons/calendar-plus';
|
||||
import ChevronLeft from '@lucide/svelte/icons/chevron-left';
|
||||
import ChevronRight from '@lucide/svelte/icons/chevron-right';
|
||||
import CircleAlert from '@lucide/svelte/icons/circle-alert';
|
||||
import Download from '@lucide/svelte/icons/download';
|
||||
import FileDown from '@lucide/svelte/icons/file-down';
|
||||
import LayoutGrid from '@lucide/svelte/icons/layout-grid';
|
||||
import List from '@lucide/svelte/icons/list';
|
||||
import MapPin from '@lucide/svelte/icons/map-pin';
|
||||
import { api, KINDS, type CalEvent, type EventValues } from '../lib/api';
|
||||
import { app, toast } from '../lib/state.svelte';
|
||||
import { dayLabel, monthEnd, monthLabel, shiftMonth, thisMonth, whenLabel } from '../lib/dates';
|
||||
import { monthEnd, monthLabel, parse, shiftMonth, thisMonth, whenLabel } from '../lib/dates';
|
||||
import { KIND_ICONS } from '../lib/icons';
|
||||
import PageHeader from '../lib/ui/PageHeader.svelte';
|
||||
import EmptyState from '../lib/ui/EmptyState.svelte';
|
||||
import Segmented from '../lib/ui/Segmented.svelte';
|
||||
import EventEditor from './EventEditor.svelte';
|
||||
import MonthGrid from './MonthGrid.svelte';
|
||||
|
||||
@@ -19,7 +33,7 @@
|
||||
});
|
||||
const calendar = $derived(calendars.find((c) => c.id === calendarId));
|
||||
const children = $derived(new Map(app.household!.children.map((c) => [c.id, c])));
|
||||
const colorFor = (e: CalEvent) => children.get(e.child_ids[0])?.color ?? calendar?.color ?? 'var(--accent)';
|
||||
const colorFor = (e: CalEvent) => children.get(e.child_ids[0])?.color ?? calendar?.color ?? 'var(--primary)';
|
||||
const byDay = $derived.by(() => {
|
||||
const days = new Map<string, CalEvent[]>();
|
||||
for (const e of events ?? []) {
|
||||
@@ -29,10 +43,12 @@
|
||||
}
|
||||
return [...days.entries()].sort();
|
||||
});
|
||||
const lastDownload = $derived(calendar?.last_exported_at ? new Date(calendar.last_exported_at.replace(' ', 'T') + 'Z') : null);
|
||||
|
||||
async function load() {
|
||||
if (!calendarId) return;
|
||||
error = '';
|
||||
events = null;
|
||||
try {
|
||||
events = await api<CalEvent[]>(`/events?calendar_id=${calendarId}&start=${month}-01&end=${monthEnd(month)}`);
|
||||
} catch (e: any) {
|
||||
@@ -65,77 +81,120 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<h1>Calendar</h1>
|
||||
<PageHeader title="Calendar" subtitle="Everything that's been published, by month." />
|
||||
|
||||
{#if !calendars.length}
|
||||
<p class="card">Add a calendar in <a href="#/settings">Settings</a> first.</p>
|
||||
<EmptyState icon={CalendarDays} title="No calendar yet">
|
||||
<p>A calendar is what you download into Apple or Google Calendar: one per child, or one for the family.</p>
|
||||
<a class="btn primary" href="#/settings">Add a calendar</a>
|
||||
</EmptyState>
|
||||
{:else}
|
||||
<div class="row">
|
||||
<select bind:value={calendarId} aria-label="Calendar" class="grow" style="width:auto">
|
||||
{#each calendars as c (c.id)}<option value={c.id}>{c.name}</option>{/each}
|
||||
</select>
|
||||
<button onclick={() => (view = view === 'list' ? 'grid' : 'list')}>{view === 'list' ? 'Month view' : 'List view'}</button>
|
||||
</div>
|
||||
|
||||
<div class="row spread month">
|
||||
<button aria-label="Previous month" onclick={() => (month = shiftMonth(month, -1))}>‹</button>
|
||||
<strong>{monthLabel(month)}</strong>
|
||||
<button aria-label="Next month" onclick={() => (month = shiftMonth(month, 1))}>›</button>
|
||||
</div>
|
||||
|
||||
<section class="card stack">
|
||||
<div class="row">
|
||||
<a class="button primary" href={`/api/calendars/${calendarId}/export.ics`} download>Download new and changed (.ics)</a>
|
||||
<a class="button" href={`/api/calendars/${calendarId}/export.ics?everything=true`} download>Download everything</a>
|
||||
<div class="stack-lg">
|
||||
<div class="controls">
|
||||
<select bind:value={calendarId} aria-label="Calendar" class="cal-select">
|
||||
{#each calendars as c (c.id)}<option value={c.id}>{c.name}</option>{/each}
|
||||
</select>
|
||||
<Segmented label="View" bind:value={view} options={[{ value: 'list', label: 'List', icon: List }, { value: 'grid', label: 'Month', icon: LayoutGrid }]} />
|
||||
</div>
|
||||
<p class="muted small">
|
||||
On iPhone, open the file and tap “Add All”. Each download holds what changed since the last one, so re-importing
|
||||
doesn't duplicate events in Apple Calendar.
|
||||
{#if calendar?.last_exported_at}Last download: {new Date(calendar.last_exported_at.replace(' ', 'T') + 'Z').toLocaleString()}.{/if}
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<div class="row" style="margin-top:12px">
|
||||
<button onclick={() => addOn(`${month}-01`)}>Add event</button>
|
||||
</div>
|
||||
{#if editing === 'new'}
|
||||
<div class="card">
|
||||
<EventEditor defaults={{ date: newDate, child_ids: calendar?.child_ids ?? [] }} onsave={add} oncancel={() => (editing = null)} />
|
||||
<section class="card export">
|
||||
<div class="export-head">
|
||||
<span class="export-icon"><FileDown size={22} aria-hidden="true" /></span>
|
||||
<div>
|
||||
<h2>Add to your phone's calendar</h2>
|
||||
<p class="hint">On iPhone, open the file and tap “Add All”. Each download holds only what changed since the last one, so nothing is duplicated.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<a class="btn primary" href={`/api/calendars/${calendarId}/export.ics`} download><Download size={18} aria-hidden="true" />New and changed</a>
|
||||
<a class="btn" href={`/api/calendars/${calendarId}/export.ics?everything=true`} download>Everything</a>
|
||||
</div>
|
||||
{#if lastDownload}<p class="hint">Last download {lastDownload.toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })}</p>{/if}
|
||||
</section>
|
||||
|
||||
<div class="month-bar">
|
||||
<button class="icon" aria-label="Previous month" onclick={() => (month = shiftMonth(month, -1))}><ChevronLeft size={22} aria-hidden="true" /></button>
|
||||
<h2 class="month-name" aria-live="polite">{monthLabel(month)}</h2>
|
||||
<button class="icon" aria-label="Next month" onclick={() => (month = shiftMonth(month, 1))}><ChevronRight size={22} aria-hidden="true" /></button>
|
||||
<span class="grow"></span>
|
||||
<button class="sm" onclick={() => addOn(`${month}-01`)}><CalendarPlus size={16} aria-hidden="true" />Add event</button>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<p class="error">{error}</p>
|
||||
{:else if events === null}
|
||||
<p class="muted">Loading…</p>
|
||||
{:else if view === 'grid'}
|
||||
<MonthGrid {month} {events} {colorFor} onday={addOn} />
|
||||
{:else if !events.length}
|
||||
<p class="empty">Nothing this month.</p>
|
||||
{:else}
|
||||
{#each byDay as [day, list] (day)}
|
||||
<h3>{dayLabel(day)}</h3>
|
||||
<ul class="events">
|
||||
{#each list as e (e.id)}
|
||||
<li class="card">
|
||||
<button class="item" onclick={() => (editing = editing === e.id ? null : e.id)} aria-expanded={editing === e.id}>
|
||||
<span class="title"><span class="dot" style:background={colorFor(e)}></span>{e.title}</span>
|
||||
<span class="muted small">{whenLabel(e)} · {KINDS[e.kind]}{e.location ? ` · ${e.location}` : ''}</span>
|
||||
</button>
|
||||
{#if editing === e.id}
|
||||
<EventEditor event={e} onsave={save(e.id)} oncancel={() => (editing = null)} ondelete={remove(e.id)} />
|
||||
{/if}
|
||||
{#if editing === 'new'}
|
||||
<div class="card">
|
||||
<h2>New event</h2>
|
||||
<EventEditor defaults={{ date: newDate, child_ids: calendar?.child_ids ?? [] }} onsave={add} oncancel={() => (editing = null)} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if error}
|
||||
<div class="alert error" role="alert"><CircleAlert size={18} aria-hidden="true" /><span>{error}</span></div>
|
||||
{:else if events === null}
|
||||
<div class="stack" aria-busy="true" aria-label="Loading events">
|
||||
{#each [1, 2, 3] as _}<div class="skeleton" style="height:64px"></div>{/each}
|
||||
</div>
|
||||
{:else if view === 'grid'}
|
||||
<MonthGrid {month} {events} {colorFor} onday={addOn} showTitle={false} />
|
||||
{:else if !events.length}
|
||||
<EmptyState icon={CalendarDays} title="Nothing this month">
|
||||
<p>Publish a scan, or add an event by hand.</p>
|
||||
</EmptyState>
|
||||
{:else}
|
||||
<ol class="agenda">
|
||||
{#each byDay as [day, list] (day)}
|
||||
{@const d = parse(day)}
|
||||
<li class="day">
|
||||
<div class="date" aria-hidden="true">
|
||||
<span class="dow">{d.toLocaleDateString(undefined, { weekday: 'short' })}</span>
|
||||
<span class="dnum tabular">{d.getDate()}</span>
|
||||
</div>
|
||||
<ul class="card-list grow">
|
||||
{#each list as e (e.id)}
|
||||
{@const KindIcon = KIND_ICONS[e.kind]}
|
||||
<li class="event" style:--child={colorFor(e)}>
|
||||
<button class="item" onclick={() => (editing = editing === e.id ? null : e.id)} aria-expanded={editing === e.id}>
|
||||
<span class="kind"><KindIcon size={18} aria-hidden="true" /></span>
|
||||
<span class="grow">
|
||||
<span class="title">{e.title}</span>
|
||||
<span class="meta">{whenLabel(e)} · {KINDS[e.kind]}{#if e.location} · <MapPin size={12} aria-hidden="true" /> {e.location}{/if}</span>
|
||||
</span>
|
||||
</button>
|
||||
{#if editing === e.id}
|
||||
<EventEditor event={e} onsave={save(e.id)} oncancel={() => (editing = null)} ondelete={remove(e.id)} />
|
||||
{/if}
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
</li>
|
||||
{/each}
|
||||
</ul>
|
||||
{/each}
|
||||
{/if}
|
||||
</ol>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.month { margin: 12px 0; }
|
||||
.month button { min-width: 44px; font-size: 1.25rem; }
|
||||
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
||||
.item { width: 100%; flex-direction: column; align-items: flex-start; gap: 2px; border: 0; padding: 4px 0; text-align: left; background: none; }
|
||||
.title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
|
||||
.controls { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; }
|
||||
.cal-select { width: auto; min-width: 200px; flex: 1 1 200px; max-width: 360px; font-weight: 600; }
|
||||
|
||||
.export { display: flex; flex-direction: column; gap: var(--s3); }
|
||||
.export-head { display: flex; gap: var(--s3); align-items: flex-start; }
|
||||
.export-icon { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: var(--r-md); background: var(--primary-soft); color: var(--primary-text); }
|
||||
.export h2 { font-size: var(--fs-md); margin-bottom: 2px; }
|
||||
|
||||
.month-bar { display: flex; align-items: center; gap: var(--s1); }
|
||||
.month-name { font-size: var(--fs-xl); min-width: 10ch; text-align: center; }
|
||||
|
||||
.agenda { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s4); }
|
||||
.agenda > .day { display: flex; gap: var(--s3); align-items: flex-start; }
|
||||
.date { flex: none; width: 52px; display: flex; flex-direction: column; align-items: center; padding-top: var(--s2); }
|
||||
.dow { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2); }
|
||||
.dnum { font-size: var(--fs-xl); font-weight: 750; line-height: 1.1; }
|
||||
|
||||
.event { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--child); border-radius: var(--r-lg); padding: var(--s1) var(--s2) var(--s1) var(--s2); box-shadow: var(--shadow-1); }
|
||||
.item { width: 100%; min-height: 56px; justify-content: flex-start; gap: var(--s3); padding: var(--s1); border: 0; background: none; text-align: left; white-space: normal; font-weight: 400; }
|
||||
.item:hover:not(:disabled) { background: none; }
|
||||
.item:active:not(:disabled) { transform: none; }
|
||||
.kind { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2); }
|
||||
.title { display: block; font-weight: 650; color: var(--text); }
|
||||
.meta { display: block; font-size: var(--fs-sm); color: var(--text-2); }
|
||||
</style>
|
||||
Reference in new issue
Block a user