diff --git a/src/pages/StatementCreation.jsx b/src/pages/StatementCreation.jsx index 2f996f3..bf344d9 100644 --- a/src/pages/StatementCreation.jsx +++ b/src/pages/StatementCreation.jsx @@ -20,14 +20,16 @@ function tokenize(text, wordMap) { } /** Replace matched words with {{uuid}} placeholders */ -function withPlaceholders(text, wordMap) { +/** Replace matched words with {{objectId}} or {{wordId}} placeholders */ +function withPlaceholders(text, wordMap, objectAssignments = {}) { if (!text) return ''; let result = text; Object.entries(wordMap) .sort((a, b) => b[0].length - a[0].length) .forEach(([title, w]) => { const re = new RegExp(`\\b${title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, 'gi'); - result = result.replace(re, `{{${w.id}}}`); + const id = objectAssignments[w.id] || w.id; + result = result.replace(re, `{{${id}}}`); }); return result; } @@ -163,7 +165,7 @@ const PAIR_TYPES = [ { value: 'word', label: 'Wort', hint: 'Frage + Positive/Negative Wörter' }, ]; -function PairForm({ objectId, onPairSaved }) { +function PairForm({ objectId, allObjects = [], onPairSaved }) { const lang = getUserLang(); const [showForm, setShowForm] = useState(false); const [savedFlash, setSavedFlash] = useState(false); @@ -182,6 +184,9 @@ function PairForm({ objectId, onPairSaved }) { // Yes/No answer const [yesNoAnswer, setYesNoAnswer] = useState(null); + // Object assignments per word: { wordId → objectId } — carried over between saves + const [objectAssignments, setObjectAssignments] = useState({}); + // Word pickers — carried over between saves const [positiveWords, setPositiveWords] = useState([]); const [negativeWords, setNegativeWords] = useState([]); @@ -246,7 +251,7 @@ function PairForm({ objectId, onPairSaved }) { let questionId = null; if (type !== 'text' && question.trim()) { const q = await apiPost('/questions', { - [`sentence_${lang}`]: withPlaceholders(question, wordMap), + [`sentence_${lang}`]: withPlaceholders(question, wordMap, objectAssignments), status: 'draft', }); questionId = q.id; @@ -257,7 +262,7 @@ function PairForm({ objectId, onPairSaved }) { if (type === 'text' || type === 'question') { const posBody = { status: 'draft' }; if (positive.trim()) - posBody[`positive_sentence_${lang}`] = withPlaceholders(positive, wordMap); + posBody[`positive_sentence_${lang}`] = withPlaceholders(positive, wordMap, objectAssignments); const s = await apiPost('/statements', posBody); posStmtId = s.id; } else if (type === 'yes_no') { @@ -274,7 +279,7 @@ function PairForm({ objectId, onPairSaved }) { // Negative statement let negStmtId = null; if (type === 'question' && negative.trim()) { - const negBody = { status: 'draft', [`negative_sentence_${lang}`]: withPlaceholders(negative, wordMap) }; + const negBody = { status: 'draft', [`negative_sentence_${lang}`]: withPlaceholders(negative, wordMap, objectAssignments) }; const s = await apiPost('/statements', negBody); negStmtId = s.id; } else if (type === 'word' && negativeWords.length) { @@ -462,13 +467,45 @@ function PairForm({ objectId, onPairSaved }) { > )} - {/* Detected words indicator — shown for all types */} + {/* Detected words — with optional object assignment per word */} {Object.keys(wordMap).length > 0 && ( -