// MultipleChoiceQuestion.tsx import React, { useState } from 'react'; import Latex from 'react-latex'; import '../questionStyle.css'; import { Button } from '@mui/material'; type Choices = { feedback: { format: string; text: string } | null; isCorrect: boolean; text: { format: string; text: string }; weigth?: number; }; interface Props { questionTitle: string | null; questionContent: string; choices: Choices[]; globalFeedback?: string | undefined; handleOnSubmitAnswer?: (answer: string) => void; showAnswer?: boolean; } const MultipleChoiceQuestion: React.FC = (props) => { const { questionTitle, questionContent, choices, showAnswer, handleOnSubmitAnswer, globalFeedback } = props; const [answer, setAnswer] = useState(); const handleOnClickAnswer = (choice: string) => { setAnswer(choice); }; const alpha = Array.from(Array(26)).map((_e, i) => i + 65); const alphabet = alpha.map((x) => String.fromCharCode(x)); return (
{questionTitle}
{questionContent}
{choices.map((choice, i) => { const selected = answer === choice.text.text ? 'selected' : ''; return (
{choice.feedback && showAnswer && (
{choice.isCorrect ? '✅' : '❌'} {choice.feedback?.text}
)}
); })}
{globalFeedback && showAnswer && (
{globalFeedback}
)} {!showAnswer && handleOnSubmitAnswer && ( )}
); }; export default MultipleChoiceQuestion;