diff --git a/src/components/AIQuiz/AIMCQQuestion.tsx b/src/components/AIQuiz/AIMCQQuestion.tsx index a7c698348..5ba752424 100644 --- a/src/components/AIQuiz/AIMCQQuestion.tsx +++ b/src/components/AIQuiz/AIMCQQuestion.tsx @@ -1,4 +1,7 @@ import type { QuizQuestion } from '../../queries/ai-quiz'; +import { useState } from 'react'; +import { cn } from '../../lib/classname'; +import { CheckIcon, XIcon, InfoIcon } from 'lucide-react'; type AIMCQQuestionProps = { question: QuizQuestion; @@ -6,16 +9,115 @@ type AIMCQQuestionProps = { export function AIMCQQuestion(props: AIMCQQuestionProps) { const { question } = props; - const { title: questionText, options } = question; + const { title: questionText, options, answerExplanation } = question; + + const [selectedOptions, setSelectedOptions] = useState([]); + const [isSubmitted, setIsSubmitted] = useState(false); + + const canSubmitMultipleAnswers = + options.filter((option) => option.isCorrect).length > 1; + + const handleSelectOption = (index: number) => { + if (!canSubmitMultipleAnswers) { + setSelectedOptions((prev) => (prev.includes(index) ? [] : [index])); + return; + } + + setSelectedOptions((prev) => { + if (prev.includes(index)) { + return prev.filter((id) => id !== index); + } + return [...prev, index]; + }); + }; + + const handleSubmit = () => { + setIsSubmitted(true); + }; + + const canSubmit = selectedOptions.length > 0; return (
-

{questionText}

-
- {options.map((option) => ( -
{option.title}
- ))} +

{questionText}

+
+ {options.map((option, index) => { + const isSelected = selectedOptions.includes(index); + const showCorrectness = isSubmitted && isSelected; + const isCorrectOption = option.isCorrect; + + const isSelectedAndCorrect = + isSubmitted && isSelected && isCorrectOption; + const isSelectedAndIncorrect = + isSubmitted && isSelected && !isCorrectOption; + const isNotSelectedAndCorrect = + isSubmitted && !isSelected && isCorrectOption; + + return ( + + ); + })}
+ + {isSubmitted && ( +
+

+ + Explanation +

+

{answerExplanation}

+
+ )} + +
); } diff --git a/src/components/AIQuiz/AIQuizContent.tsx b/src/components/AIQuiz/AIQuizContent.tsx index 49f6dc406..3a8c02fa9 100644 --- a/src/components/AIQuiz/AIQuizContent.tsx +++ b/src/components/AIQuiz/AIQuizContent.tsx @@ -22,8 +22,8 @@ export function AIQuizContent(props: AIQuizContentProps) { const hasPreviousQuestions = activeQuestionIndex > 0; return ( -
-
+
+
setActiveQuestionIndex(activeQuestionIndex - 1)}