refactor(journey-editor): extract scheduleAnnounceReset; comment no-op items=prev in add handlers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-06-09 19:08:27 +02:00
parent d689a66275
commit 0130c4fa99

View File

@@ -41,6 +41,14 @@ let mutationError = $state('');
let liveAnnounce = $state('');
let announceTimer: ReturnType<typeof setTimeout> | 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') {