// MultipleChoiceQuestion.tsx import React, { useEffect, useState } from 'react'; import '../questionStyle.css'; import { Button } from '@mui/material'; import textType, { formatLatex } from '../../GiftTemplate/templates/TextType'; import { TextFormat } from '../../GiftTemplate/templates/types'; // import Latex from 'react-latex'; type Choices = { feedback: { format: string; text: string } | null; isCorrect: boolean; text: { format: string; text: string }; weigth?: number; }; interface Props { questionStem: TextFormat; choices: Choices[]; globalFeedback?: string | undefined; handleOnSubmitAnswer?: (answer: string) => void; showAnswer?: boolean; } const MultipleChoiceQuestion: React.FC = (props) => { const { questionStem: questionContent, choices, showAnswer, handleOnSubmitAnswer, globalFeedback } = props; const [answer, setAnswer] = useState(); useEffect(() => { setAnswer(undefined); }, [questionContent]); 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 (
{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;