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:
@@ -41,6 +41,14 @@ let mutationError = $state('');
|
|||||||
let liveAnnounce = $state('');
|
let liveAnnounce = $state('');
|
||||||
let announceTimer: ReturnType<typeof setTimeout> | null = null;
|
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 titleEmpty = $derived(title.trim().length === 0);
|
||||||
const showTitleError = $derived(titleEmpty && titleTouched);
|
const showTitleError = $derived(titleEmpty && titleTouched);
|
||||||
const isDraft = $derived(status === 'DRAFT');
|
const isDraft = $derived(status === 'DRAFT');
|
||||||
@@ -93,7 +101,7 @@ async function handleAddDocument(doc: DocumentOption) {
|
|||||||
const newItem: JourneyItemView = await res.json();
|
const newItem: JourneyItemView = await res.json();
|
||||||
items = [...items, newItem];
|
items = [...items, newItem];
|
||||||
} catch {
|
} catch {
|
||||||
items = prev;
|
items = prev; // prev === items here (add is pessimistic); kept for symmetry with optimistic handlers
|
||||||
mutationError = m.journey_mutation_error_reload();
|
mutationError = m.journey_mutation_error_reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,7 +119,7 @@ async function handleAddInterlude(text: string) {
|
|||||||
const newItem: JourneyItemView = await res.json();
|
const newItem: JourneyItemView = await res.json();
|
||||||
items = [...items, newItem];
|
items = [...items, newItem];
|
||||||
} catch {
|
} catch {
|
||||||
items = prev;
|
items = prev; // prev === items here (add is pessimistic); kept for symmetry with optimistic handlers
|
||||||
mutationError = m.journey_mutation_error_reload();
|
mutationError = m.journey_mutation_error_reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,12 +160,7 @@ async function handleMoveUp(index: number) {
|
|||||||
newPosition: index
|
newPosition: index
|
||||||
});
|
});
|
||||||
await handleReorder(ids);
|
await handleReorder(ids);
|
||||||
// Clear so the live region does not re-announce on unrelated DOM mutations
|
scheduleAnnounceReset();
|
||||||
if (announceTimer) clearTimeout(announceTimer);
|
|
||||||
announceTimer = setTimeout(() => {
|
|
||||||
liveAnnounce = '';
|
|
||||||
announceTimer = null;
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleMoveDown(index: number) {
|
async function handleMoveDown(index: number) {
|
||||||
@@ -170,12 +173,7 @@ async function handleMoveDown(index: number) {
|
|||||||
newPosition: index + 2
|
newPosition: index + 2
|
||||||
});
|
});
|
||||||
await handleReorder(ids);
|
await handleReorder(ids);
|
||||||
// Clear so the live region does not re-announce on unrelated DOM mutations
|
scheduleAnnounceReset();
|
||||||
if (announceTimer) clearTimeout(announceTimer);
|
|
||||||
announceTimer = setTimeout(() => {
|
|
||||||
liveAnnounce = '';
|
|
||||||
announceTimer = null;
|
|
||||||
}, 500);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function save(nextStatus: 'DRAFT' | 'PUBLISHED') {
|
async function save(nextStatus: 'DRAFT' | 'PUBLISHED') {
|
||||||
|
|||||||
Reference in New Issue
Block a user