// Question;tsx import React, { useMemo } from 'react'; import { GIFTQuestion } from 'gift-pegjs'; import TrueFalseQuestion from './TrueFalseQuestion/TrueFalseQuestion'; import MultipleChoiceQuestion from './MultipleChoiceQuestion/MultipleChoiceQuestion'; import NumericalQuestion from './NumericalQuestion/NumericalQuestion'; import ShortAnswerQuestion from './ShortAnswerQuestion/ShortAnswerQuestion'; import useCheckMobileScreen from '../../services/useCheckMobileScreen'; interface QuestionProps { question: GIFTQuestion | undefined; handleOnSubmitAnswer?: (answer: string | number | boolean) => void; showAnswer?: boolean; imageUrl?: string; } const Question: React.FC = ({ question, handleOnSubmitAnswer, showAnswer, imageUrl }) => { const isMobile = useCheckMobileScreen(); const imgWidth = useMemo(() => { return isMobile ? '100%' : '20%'; }, [isMobile]); let questionTypeComponent = null; switch (question?.type) { case 'TF': questionTypeComponent = ( ); break; case 'MC': questionTypeComponent = ( ({ ...choice, id: index.toString() }))} handleOnSubmitAnswer={handleOnSubmitAnswer} showAnswer={showAnswer} globalFeedback={question.globalFeedback?.text} /> ); break; case 'Numerical': if (question.choices) { if (!Array.isArray(question.choices)) { questionTypeComponent = ( ); } else { questionTypeComponent = ( ); } } break; case 'Short': questionTypeComponent = ( ({ ...choice, id: index.toString() }))} handleOnSubmitAnswer={handleOnSubmitAnswer} showAnswer={showAnswer} globalFeedback={question.globalFeedback?.text} /> ); break; } return (
{questionTypeComponent ? ( <> {imageUrl && ( QuestionImage )} {questionTypeComponent} ) : (
Question de type inconnue
)}
); }; export default Question;