2025-01-23 22:38:22 -05:00
|
|
|
// Question;tsx
|
2025-01-24 14:51:58 -05:00
|
|
|
import React from 'react';
|
2025-01-23 22:38:22 -05:00
|
|
|
import { Question } from 'gift-pegjs';
|
|
|
|
|
|
|
|
|
|
import TrueFalseQuestion from './TrueFalseQuestion/TrueFalseQuestion';
|
|
|
|
|
import MultipleChoiceQuestionDisplay from './MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay';
|
2025-01-24 14:51:58 -05:00
|
|
|
import NumericalQuestionDisplay from './NumericalQuestionDisplay/NumericalQuestionDisplay';
|
|
|
|
|
import ShortAnswerQuestionDisplay from './ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
|
|
|
|
// import useCheckMobileScreen from '../../services/useCheckMobileScreen';
|
2025-01-23 22:38:22 -05:00
|
|
|
|
|
|
|
|
interface QuestionProps {
|
|
|
|
|
question: Question;
|
|
|
|
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
|
|
|
|
showAnswer?: boolean;
|
|
|
|
|
}
|
|
|
|
|
const QuestionDisplay: React.FC<QuestionProps> = ({
|
|
|
|
|
question,
|
|
|
|
|
handleOnSubmitAnswer,
|
|
|
|
|
showAnswer,
|
|
|
|
|
}) => {
|
2025-01-24 14:51:58 -05:00
|
|
|
// const isMobile = useCheckMobileScreen();
|
|
|
|
|
// const imgWidth = useMemo(() => {
|
|
|
|
|
// return isMobile ? '100%' : '20%';
|
|
|
|
|
// }, [isMobile]);
|
2025-01-23 22:38:22 -05:00
|
|
|
|
|
|
|
|
let questionTypeComponent = null;
|
|
|
|
|
switch (question?.type) {
|
|
|
|
|
case 'TF':
|
|
|
|
|
questionTypeComponent = (
|
|
|
|
|
<TrueFalseQuestion
|
|
|
|
|
questionContent={question.formattedStem}
|
|
|
|
|
correctAnswer={question.isTrue}
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
globalFeedback={question.formattedGlobalFeedback?.text}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case 'MC':
|
|
|
|
|
questionTypeComponent = (
|
|
|
|
|
<MultipleChoiceQuestionDisplay
|
|
|
|
|
question={question}
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case 'Numerical':
|
|
|
|
|
if (question.choices) {
|
|
|
|
|
if (!Array.isArray(question.choices)) {
|
|
|
|
|
questionTypeComponent = (
|
2025-01-24 14:51:58 -05:00
|
|
|
<NumericalQuestionDisplay
|
|
|
|
|
question={question}
|
2025-01-23 22:38:22 -05:00
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
questionTypeComponent = ( // TODO fix NumericalQuestion (correctAnswers is borked)
|
2025-01-24 14:51:58 -05:00
|
|
|
<NumericalQuestionDisplay
|
|
|
|
|
question={question}
|
2025-01-23 22:38:22 -05:00
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'Short':
|
|
|
|
|
questionTypeComponent = (
|
2025-01-24 14:51:58 -05:00
|
|
|
<ShortAnswerQuestionDisplay
|
|
|
|
|
question={question}
|
2025-01-23 22:38:22 -05:00
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="question-container">
|
|
|
|
|
{questionTypeComponent ? (
|
|
|
|
|
<>
|
|
|
|
|
{questionTypeComponent}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<div>Question de type inconnue</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default QuestionDisplay;
|