Update QuestionRenderer to handle showResult and lastCorrect states

This commit is contained in:
2026-01-08 01:21:20 +01:00
parent 69630e62ec
commit e62f1cfd32

View File

@@ -91,13 +91,18 @@ function QuestionRenderer({
question, question,
response, response,
onChange, onChange,
showResult,
lastCorrect,
}: { }: {
question: QuizQuestionWithEntry; question: QuizQuestionWithEntry;
response: any; response: any;
onChange: (val: any) => void; onChange: (val: any) => void;
showResult: boolean;
lastCorrect: boolean;
}) { }) {
const payload = question.payload || {}; const payload = question.payload || {};
const type = question.type || ''; const type = question.type || '';
const correctIndex = typeof question.answer?.correct_index === 'number' ? question.answer.correct_index : null;
if (type === 'cloze') { if (type === 'cloze') {
const sentence = payload.sentence_jp || payload.sentence || ''; const sentence = payload.sentence_jp || payload.sentence || '';
@@ -157,7 +162,14 @@ function QuestionRenderer({
return ( return (
<div className="question-block"> <div className="question-block">
{options.map((option, idx) => ( {options.map((option, idx) => (
<label key={idx} className="option"> <label
key={idx}
className={[
'option',
showResult && correctIndex === idx ? 'correct' : '',
showResult && !lastCorrect && response === idx && correctIndex !== idx ? 'incorrect' : '',
].join(' ').trim()}
>
<input <input
type="radio" type="radio"
checked={response === idx} checked={response === idx}