refactor(journey-editor): extract appendItem from the two add handlers
All checks were successful
CI / Unit & Component Tests (pull_request) Successful in 4m13s
CI / OCR Service Tests (pull_request) Successful in 22s
CI / Backend Unit Tests (pull_request) Successful in 4m24s
CI / fail2ban Regex (pull_request) Successful in 46s
CI / Semgrep Security Scan (pull_request) Successful in 27s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m5s
All checks were successful
CI / Unit & Component Tests (pull_request) Successful in 4m13s
CI / OCR Service Tests (pull_request) Successful in 22s
CI / Backend Unit Tests (pull_request) Successful in 4m24s
CI / fail2ban Regex (pull_request) Successful in 46s
CI / Semgrep Security Scan (pull_request) Successful in 27s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m5s
handleAddDocument/handleAddInterlude were identical except the POST body. Behavior unchanged — all 35 editor specs stay green. Review round 3: Felix suggestion. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit was merged in pull request #792.
This commit is contained in:
@@ -125,13 +125,14 @@ async function handleReorder(itemIds: string[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleAddDocument(doc: DocumentOption) {
|
/** Pessimistic append shared by both add paths — items update only on API success. */
|
||||||
|
async function appendItem(body: { documentId?: string; note?: string }) {
|
||||||
mutationError = '';
|
mutationError = '';
|
||||||
try {
|
try {
|
||||||
const res = await csrfFetch(`/api/geschichten/${geschichte.id}/items`, {
|
const res = await csrfFetch(`/api/geschichten/${geschichte.id}/items`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ documentId: doc.id })
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
mutationError = await failureMessage(res);
|
mutationError = await failureMessage(res);
|
||||||
@@ -142,31 +143,17 @@ async function handleAddDocument(doc: DocumentOption) {
|
|||||||
// Move-up is disabled on the first row — fall back to the remove button then.
|
// Move-up is disabled on the first row — fall back to the remove button then.
|
||||||
await focusRowControl(newItem.id, '[data-move-up]:not([disabled]), [data-remove-btn]');
|
await focusRowControl(newItem.id, '[data-move-up]:not([disabled]), [data-remove-btn]');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Journey add document failed', e);
|
console.error('Journey item append failed', e);
|
||||||
mutationError = m.journey_mutation_error_reload();
|
mutationError = m.journey_mutation_error_reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function handleAddDocument(doc: DocumentOption) {
|
||||||
|
await appendItem({ documentId: doc.id });
|
||||||
|
}
|
||||||
|
|
||||||
async function handleAddInterlude(text: string) {
|
async function handleAddInterlude(text: string) {
|
||||||
mutationError = '';
|
await appendItem({ note: text });
|
||||||
try {
|
|
||||||
const res = await csrfFetch(`/api/geschichten/${geschichte.id}/items`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: { 'Content-Type': 'application/json' },
|
|
||||||
body: JSON.stringify({ note: text })
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
mutationError = await failureMessage(res);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const newItem: JourneyItemView = await res.json();
|
|
||||||
items = [...items, newItem];
|
|
||||||
// Move-up is disabled on the first row — fall back to the remove button then.
|
|
||||||
await focusRowControl(newItem.id, '[data-move-up]:not([disabled]), [data-remove-btn]');
|
|
||||||
} catch (e) {
|
|
||||||
console.error('Journey add interlude failed', e);
|
|
||||||
mutationError = m.journey_mutation_error_reload();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleRemove(itemId: string) {
|
async function handleRemove(itemId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user