fix(journey-editor): selectedPersons change calls markDirty via $effect

Skip-first-run $effect tracks selectedPersons array length; any add/remove
after mount marks the editor dirty so the unsaved-warning fires on nav.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-10 19:39:44 +02:00
parent 7ad2132a92
commit 166003b33a
2 changed files with 50 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ let { geschichte, onSubmit, submitting = false }: Props = $props();
const unsaved = createUnsavedWarning();
let title = $state(geschichte.title ?? '');
let body = $state(geschichte.body ?? '');
let status: 'DRAFT' | 'PUBLISHED' = $state(geschichte.status ?? 'DRAFT');
let selectedPersons: PersonOption[] = $state(
@@ -64,6 +65,17 @@ const alreadyAddedIds = $derived(
const canPublish = $derived(items.length > 0 && !titleEmpty);
const showPublishedEmptyWarning = $derived(status === 'PUBLISHED' && items.length === 0);
// Skip the initial run so mounting with pre-existing persons doesn't mark dirty.
let _personEffectMounted = false;
$effect(() => {
void selectedPersons.length;
if (!_personEffectMounted) {
_personEffectMounted = true;
return;
}
unsaved.markDirty();
});
let listEl: HTMLElement | null = $state(null);
let editorColEl: HTMLElement | null = $state(null);