Timed pack lunch with two alerts, one-tap delete, multi-day events in the list, merge consecutive days
This commit is contained in:
1 parent
bb47aff609
commit
1817cb50d4
8 files changed
+61
-19
No files matched your search
@@ -26,6 +26,8 @@
|
||||
let events = $state<CalEvent[] | null>(null);
|
||||
let editing = $state<number | 'new' | null>(null);
|
||||
let newDate = $state('');
|
||||
let editDay = $state(''); // a multi-day event is listed on each day; its editor opens under the one tapped
|
||||
const isOpen = (e: CalEvent, day: string) => editing === e.id && editDay === day;
|
||||
let error = $state('');
|
||||
|
||||
$effect(() => {
|
||||
@@ -36,10 +38,14 @@
|
||||
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[]>();
|
||||
const last = monthEnd(month);
|
||||
for (const e of events ?? []) {
|
||||
const key = e.date < `${month}-01` ? `${month}-01` : e.date; // multi-day events that began last month
|
||||
if (!days.has(key)) days.set(key, []);
|
||||
days.get(key)!.push(e);
|
||||
// A multi-day event shows on each of its days in this month.
|
||||
for (let d = parse(e.date < `${month}-01` ? `${month}-01` : e.date); iso(d) <= (e.end_date ?? e.date) && iso(d) <= last; d.setDate(d.getDate() + 1)) {
|
||||
const key = iso(d);
|
||||
if (!days.has(key)) days.set(key, []);
|
||||
days.get(key)!.push(e);
|
||||
}
|
||||
}
|
||||
return [...days.entries()].sort();
|
||||
});
|
||||
@@ -156,14 +162,14 @@
|
||||
{#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}>
|
||||
<button class="item" onclick={() => { editing = isOpen(e, day) ? null : e.id; editDay = day; }} aria-expanded={isOpen(e, day)}>
|
||||
<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}
|
||||
{#if isOpen(e, day)}
|
||||
<EventEditor event={e} onsave={save(e.id)} oncancel={() => (editing = null)} ondelete={remove(e.id)} />
|
||||
{/if}
|
||||
</li>
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
child_ids: [...(initial.child_ids ?? [])],
|
||||
});
|
||||
let saving = $state(false);
|
||||
let confirmDelete = $state(false);
|
||||
const kinds = $derived(Object.entries(KINDS).filter(([k]) => k !== 'pack_lunch' || f.kind === 'pack_lunch'));
|
||||
const uid = untrack(() => event?.id ?? 'new');
|
||||
|
||||
@@ -130,11 +129,7 @@
|
||||
<button type="button" class="ghost" onclick={oncancel}>Cancel</button>
|
||||
</div>
|
||||
{#if ondelete}
|
||||
{#if confirmDelete}
|
||||
<button type="button" class="danger solid" onclick={ondelete}><Trash2 size={18} aria-hidden="true" />Delete event</button>
|
||||
{:else}
|
||||
<button type="button" class="danger" onclick={() => (confirmDelete = true)}><Trash2 size={18} aria-hidden="true" />Delete…</button>
|
||||
{/if}
|
||||
<button type="button" class="danger" onclick={ondelete}><Trash2 size={18} aria-hidden="true" />Delete</button>
|
||||
{/if}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
Reference in new issue
Block a user