From ead05c682654d98d1f9a03fe199f73df7445ef58 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Thu, 8 Jan 2026 03:00:16 +0100 Subject: [PATCH] Add formatUserAnswer function to QuizRunner.tsx --- client/src/components/QuizRunner.tsx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client/src/components/QuizRunner.tsx b/client/src/components/QuizRunner.tsx index 7b1978c..035debf 100644 --- a/client/src/components/QuizRunner.tsx +++ b/client/src/components/QuizRunner.tsx @@ -100,6 +100,28 @@ function deriveCorrectText(question: QuizQuestionWithEntry, userResponse: any) { return ''; } +function formatUserAnswer(question: QuizQuestionWithEntry, userResponse: any) { + const type = question.type || ''; + if (type === 'cloze') { + return userResponse || 'No answer'; + } + if (type === 'match') { + const pairs: any[] = Array.isArray(question.payload?.pairs) ? question.payload.pairs : []; + if (!pairs.length) return 'No answer'; + return pairs + .map((pair, idx) => { + const picked = userResponse?.[idx]; + return `${pair.left} → ${picked || '—'}`; + }) + .join(' | '); + } + const options: any[] = Array.isArray(question.payload?.options) ? question.payload.options : []; + if (((type || '').startsWith('mc') || type === 'choose_best_reply' || !type) && typeof userResponse === 'number') { + return options[userResponse] ?? `Option ${userResponse}`; + } + return userResponse ?? 'No answer'; +} + function checkClozeAnswer(question: QuizQuestionWithEntry, response: string) { if (!response) return false; const expected = [question.answer?.correct_text, question.answer?.correct, question.payload?.blanked].filter(Boolean).map(normalize);