fix: use allObjects._words to restore objectAssignments on EditPairForm load

Replace async word search with synchronous lookup via allObjects._words,
which is already populated. Eliminates race conditions and fetch failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-28 22:19:56 +02:00
parent 08d22a1440
commit 7564f23ef1

View File

@@ -531,19 +531,18 @@ function EditPairForm({ pair, allObjects, onSaved, onCancel, onDeleted }) {
} }
} }
// Directly look up word IDs for each extracted label and set objectAssignments // Look up word IDs via allObjects._words (already loaded, no fetch needed)
if (Object.keys(labelToObjId).length) { if (Object.keys(labelToObjId).length) {
const assignments = {}; const assignments = {};
await Promise.all(Object.entries(labelToObjId).map(async ([label, objId]) => { Object.entries(labelToObjId).forEach(([label, objId]) => {
try { const obj = (allObjects || []).find(o => o.id === objId);
const words = await apiFetch(`/words?search=${encodeURIComponent(label)}&limit=5`); const word = (obj?._words || []).find(w =>
const word = Array.isArray(words) && words.find(w => (w.titel_de || '').toLowerCase() === label ||
(w.titel_de || '').toLowerCase() === label || (w.titel_en || '').toLowerCase() === label ||
(w.titel_en || '').toLowerCase() === label (w.titel_sv || '').toLowerCase() === label
); );
if (word) assignments[word.id] = objId; if (word) assignments[word.id] = objId;
} catch { /* ignore */ } });
}));
if (Object.keys(assignments).length) setObjectAssignments(assignments); if (Object.keys(assignments).length) setObjectAssignments(assignments);
} }
} catch (e) { console.error(e); } } catch (e) { console.error(e); }