Redesign event editor

This commit is contained in:
iamdoubz committed 2026-11-05 17:41:34 -06:00
1 parent b770152d1c
commit 65ac86cc06
1 file changed
+57 -34
+57 -34
View File
@@ -1,6 +1,9 @@
<script lang="ts">
import { KINDS, type CalEvent, type EventValues as Values } from '../lib/api';
import Check from '@lucide/svelte/icons/check';
import Quote from '@lucide/svelte/icons/quote';
import Trash2 from '@lucide/svelte/icons/trash-2';
import { untrack } from 'svelte';
import { KINDS, type CalEvent, type EventValues as Values } from '../lib/api';
import { app } from '../lib/state.svelte';
let {
@@ -34,6 +37,7 @@
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');
async function submit(e: SubmitEvent) {
e.preventDefault();
@@ -56,77 +60,96 @@
<form class="editor" onsubmit={submit}>
{#if event?.source_text}
<p class="muted small">On the page: “{event.source_text}”</p>
<p class="source"><Quote size={14} aria-hidden="true" /><span>On the page: “{event.source_text}”</span></p>
{/if}
<div class="field">
<label for="title-{event?.id ?? 'new'}">Title</label>
<input id="title-{event?.id ?? 'new'}" bind:value={f.title} required maxlength="80" />
<label class="label" for="title-{uid}">Title</label>
<input id="title-{uid}" bind:value={f.title} required maxlength="80" />
</div>
<div class="fields">
<div class="field">
<label for="date-{event?.id ?? 'new'}">Date</label>
<input id="date-{event?.id ?? 'new'}" type="date" bind:value={f.date} required />
<label class="label" for="date-{uid}">Date</label>
<input id="date-{uid}" type="date" bind:value={f.date} required />
</div>
<div class="field">
<label for="end-{event?.id ?? 'new'}">Last day (multi-day)</label>
<input id="end-{event?.id ?? 'new'}" type="date" bind:value={f.end_date} min={f.date} />
<label class="label" for="end-{uid}">Last day <span class="hint">(multi-day)</span></label>
<input id="end-{uid}" type="date" bind:value={f.end_date} min={f.date} />
</div>
<div class="field">
<label for="kind-{event?.id ?? 'new'}">Kind</label>
<select id="kind-{event?.id ?? 'new'}" bind:value={f.kind}>
{#each kinds as [value, label]}
<option {value}>{label}</option>
{/each}
<label class="label" for="kind-{uid}">Kind</label>
<select id="kind-{uid}" bind:value={f.kind}>
{#each kinds as [value, label]}<option {value}>{label}</option>{/each}
</select>
</div>
</div>
<label class="check"><input type="checkbox" bind:checked={f.all_day} /> All day</label>
<label class="switch">
<input type="checkbox" role="switch" bind:checked={f.all_day} />
<span class="track" aria-hidden="true"><span class="thumb"></span></span>
<span>All day</span>
</label>
{#if !f.all_day}
<div class="fields">
<div class="field">
<label for="start-{event?.id ?? 'new'}">Starts</label>
<input id="start-{event?.id ?? 'new'}" type="time" bind:value={f.start_time} required />
<label class="label" for="start-{uid}">Starts</label>
<input id="start-{uid}" type="time" bind:value={f.start_time} required />
</div>
<div class="field">
<label for="stop-{event?.id ?? 'new'}">Ends (optional)</label>
<input id="stop-{event?.id ?? 'new'}" type="time" bind:value={f.end_time} />
<label class="label" for="stop-{uid}">Ends <span class="hint">(optional)</span></label>
<input id="stop-{uid}" type="time" bind:value={f.end_time} />
</div>
</div>
{/if}
<fieldset class="field">
<legend class="muted small">For</legend>
<legend class="label">For</legend>
<div class="row">
{#each app.household!.children as c (c.id)}
<label class="check"><input type="checkbox" bind:group={f.child_ids} value={c.id} /><span class="dot" style:background={c.color}></span>{c.display_name}</label>
<label class="chip-check">
<input type="checkbox" bind:group={f.child_ids} value={c.id} />
<span class="dot" style:background={c.color}></span>{c.display_name}
</label>
{/each}
</div>
</fieldset>
<div class="fields">
<div class="field">
<label for="loc-{event?.id ?? 'new'}">Location</label>
<input id="loc-{event?.id ?? 'new'}" bind:value={f.location} maxlength="200" />
</div>
<div class="field">
<label class="label" for="loc-{uid}">Location</label>
<input id="loc-{uid}" bind:value={f.location} maxlength="200" />
</div>
<div class="field">
<label for="notes-{event?.id ?? 'new'}">Notes</label>
<textarea id="notes-{event?.id ?? 'new'}" bind:value={f.notes} maxlength="2000"></textarea>
<label class="label" for="notes-{uid}">Notes</label>
<textarea id="notes-{uid}" bind:value={f.notes} maxlength="2000"></textarea>
</div>
<div class="row spread">
<div class="footer">
<div class="row">
<button class="primary" type="submit" disabled={saving}>Save</button>
<button type="button" onclick={oncancel}>Cancel</button>
<button class="primary" type="submit" disabled={saving}><Check size={18} aria-hidden="true" />Save</button>
<button type="button" class="ghost" onclick={oncancel}>Cancel</button>
</div>
{#if ondelete}
{#if confirmDelete}
<button type="button" class="danger" onclick={ondelete}>Delete event</button>
<button type="button" class="danger solid" onclick={ondelete}><Trash2 size={18} aria-hidden="true" />Delete event</button>
{:else}
<button type="button" class="quiet" onclick={() => (confirmDelete = true)}>Delete…</button>
<button type="button" class="danger" onclick={() => (confirmDelete = true)}><Trash2 size={18} aria-hidden="true" />Delete…</button>
{/if}
{/if}
</div>
</form>
<style>
.editor { padding: 12px 0 4px; border-top: 1px dashed var(--border); margin-top: 8px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
.editor { display: flex; flex-direction: column; gap: var(--s4); padding: var(--s4) var(--s2) var(--s2); margin-top: var(--s2); border-top: 1px solid var(--border); }
.source { display: flex; gap: var(--s2); align-items: flex-start; padding: var(--s2) var(--s3); border-radius: var(--r-md); background: var(--surface-2); color: var(--text-2); font-size: var(--fs-sm); }
.source :global(svg) { flex: none; margin-top: 3px; }
.footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); padding-top: var(--s2); }
.switch { display: inline-flex; align-items: center; gap: var(--s3); min-height: 44px; cursor: pointer; font-weight: 600; align-self: flex-start; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { position: relative; width: 44px; height: 26px; border-radius: var(--r-full); background: var(--surface-3); border: 1px solid var(--border-strong); transition: background-color var(--dur) var(--ease); }
.thumb { position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-1); transition: transform var(--dur) var(--ease); }
.switch input:checked + .track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .track .thumb { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 3px solid var(--primary); outline-offset: 2px; }
</style>