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') {