From 0130c4fa9914b9e1feeb79334812fbbc14dae7e4 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 9 Jun 2026 19:08:27 +0200 Subject: [PATCH] refactor(journey-editor): extract scheduleAnnounceReset; comment no-op items=prev in add handlers Co-Authored-By: Claude Sonnet 4.6 --- .../src/lib/geschichte/JourneyEditor.svelte | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/frontend/src/lib/geschichte/JourneyEditor.svelte b/frontend/src/lib/geschichte/JourneyEditor.svelte index 0427759e..2d50e902 100644 --- a/frontend/src/lib/geschichte/JourneyEditor.svelte +++ b/frontend/src/lib/geschichte/JourneyEditor.svelte @@ -41,6 +41,14 @@ let mutationError = $state(''); let liveAnnounce = $state(''); let announceTimer: ReturnType | null = null; +function scheduleAnnounceReset() { + if (announceTimer) clearTimeout(announceTimer); + announceTimer = setTimeout(() => { + liveAnnounce = ''; + announceTimer = null; + }, 500); +} + const titleEmpty = $derived(title.trim().length === 0); const showTitleError = $derived(titleEmpty && titleTouched); const isDraft = $derived(status === 'DRAFT'); @@ -93,7 +101,7 @@ async function handleAddDocument(doc: DocumentOption) { const newItem: JourneyItemView = await res.json(); items = [...items, newItem]; } catch { - items = prev; + items = prev; // prev === items here (add is pessimistic); kept for symmetry with optimistic handlers mutationError = m.journey_mutation_error_reload(); } } @@ -111,7 +119,7 @@ async function handleAddInterlude(text: string) { const newItem: JourneyItemView = await res.json(); items = [...items, newItem]; } catch { - items = prev; + items = prev; // prev === items here (add is pessimistic); kept for symmetry with optimistic handlers mutationError = m.journey_mutation_error_reload(); } } @@ -152,12 +160,7 @@ async function handleMoveUp(index: number) { newPosition: index }); await handleReorder(ids); - // Clear so the live region does not re-announce on unrelated DOM mutations - if (announceTimer) clearTimeout(announceTimer); - announceTimer = setTimeout(() => { - liveAnnounce = ''; - announceTimer = null; - }, 500); + scheduleAnnounceReset(); } async function handleMoveDown(index: number) { @@ -170,12 +173,7 @@ async function handleMoveDown(index: number) { newPosition: index + 2 }); await handleReorder(ids); - // Clear so the live region does not re-announce on unrelated DOM mutations - if (announceTimer) clearTimeout(announceTimer); - announceTimer = setTimeout(() => { - liveAnnounce = ''; - announceTimer = null; - }, 500); + scheduleAnnounceReset(); } async function save(nextStatus: 'DRAFT' | 'PUBLISHED') {