From bc02d22270f8144d6bc40a7838fdb07c145590c5 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 14 Jun 2026 09:13:17 +0200 Subject: [PATCH] refactor(timeline): drop EventForm's redundant `type` state The submitted type comes from EventTypeSelect's own hidden input; EventForm's `type` $state was only read to seed `value=` and the onchange reassignment had no downstream reader. Inline the seed expression and pass markDirty directly, removing the second source of truth. Co-Authored-By: Claude Opus 4.8 --- frontend/src/lib/timeline/EventForm.svelte | 10 +++++----- frontend/src/lib/timeline/EventForm.svelte.spec.ts | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/frontend/src/lib/timeline/EventForm.svelte b/frontend/src/lib/timeline/EventForm.svelte index 9cf675d1..36c9296f 100644 --- a/frontend/src/lib/timeline/EventForm.svelte +++ b/frontend/src/lib/timeline/EventForm.svelte @@ -61,7 +61,6 @@ let { // won't update the form — the two dedicated routes always remount, which is fine. let title = $state(form?.title ?? event?.title ?? ''); let description = $state(form?.description ?? event?.description ?? ''); -let type = $state(form?.type ?? event?.type ?? 'PERSONAL'); let dateIso = $state(form?.eventDate ?? event?.eventDate ?? ''); let precision = $state( (form?.precision as DatePrecision) ?? (event?.precision as DatePrecision) ?? 'DAY' @@ -212,10 +211,11 @@ function markDirty() { {m.event_editor_type_label()} - { - type = t; - markDirty(); - }} /> +
diff --git a/frontend/src/lib/timeline/EventForm.svelte.spec.ts b/frontend/src/lib/timeline/EventForm.svelte.spec.ts index 2962df86..d083bda9 100644 --- a/frontend/src/lib/timeline/EventForm.svelte.spec.ts +++ b/frontend/src/lib/timeline/EventForm.svelte.spec.ts @@ -62,6 +62,20 @@ describe('EventForm — date precision RANGE reveal (headline AC, REQ-008/009)', }); }); +describe('EventForm — type seeding (review #8 refactor fence)', () => { + it('seeds the type selector from the event so the submitted type is correct', async () => { + renderForm({ event: makeEvent({ type: 'HISTORICAL' }) }); + const hidden = document.querySelector('input[type="hidden"][name="type"]') as HTMLInputElement; + expect(hidden.value).toBe('HISTORICAL'); + }); + + it('prefers the fail-payload type over the seeded event', async () => { + renderForm({ event: makeEvent({ type: 'PERSONAL' }), form: { type: 'HISTORICAL' } }); + const hidden = document.querySelector('input[type="hidden"][name="type"]') as HTMLInputElement; + expect(hidden.value).toBe('HISTORICAL'); + }); +}); + describe('EventForm — picker preselect (REQ-014)', () => { it('preselects a person when initialPersons is provided', async () => { renderForm({ initialPersons: [{ id: 'p1', displayName: 'Anna Müller' }] });