From 72347e0b8ed9eea2079edc935b6424df0dbee61d Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 8 Jan 2026 02:44:15 +0100 Subject: [PATCH] Update QuizRunner to handle match type questions with user responses --- client/src/components/QuizRunner.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/client/src/components/QuizRunner.tsx b/client/src/components/QuizRunner.tsx index 02122a6..cd83f2e 100644 --- a/client/src/components/QuizRunner.tsx +++ b/client/src/components/QuizRunner.tsx @@ -68,11 +68,29 @@ function resolveTargets(question: QuizQuestionWithEntry): TargetHit[] { return found; } -function deriveCorrectText(question: QuizQuestionWithEntry) { +function deriveCorrectText(question: QuizQuestionWithEntry, userResponse: any) { const options: any[] = Array.isArray(question.payload?.options) ? question.payload?.options : []; if (typeof question.answer?.correct_index === 'number' && options[question.answer.correct_index]) { return options[question.answer.correct_index]; } + + if (question.type === 'match') { + const pairs: any[] = Array.isArray(question.payload?.pairs) ? question.payload.pairs : []; + if (!pairs.length) return ''; + const messages: string[] = []; + pairs.forEach((pair, idx) => { + const correct = pair.right; + const picked = userResponse?.[idx]; + if (picked !== correct) { + messages.push(`${pair.left} → ${correct}${picked ? ` (you picked ${picked})` : ''}`); + } + }); + if (messages.length === 0) { + return pairs.map((p: any) => `${p.left} → ${p.right}`).join(' | '); + } + return messages.join(' | '); + } + if (question.answer?.correct_text) return question.answer.correct_text; if (question.payload?.blanked) return question.payload.blanked; const pairs = Array.isArray(question.payload?.pairs) ? question.payload.pairs : [];