2024-03-29 20:08:34 -04:00
|
|
|
// 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<QuestionProps> = ({
|
|
|
|
|
question,
|
|
|
|
|
handleOnSubmitAnswer,
|
|
|
|
|
showAnswer,
|
|
|
|
|
imageUrl
|
|
|
|
|
}) => {
|
|
|
|
|
const isMobile = useCheckMobileScreen();
|
|
|
|
|
const imgWidth = useMemo(() => {
|
|
|
|
|
return isMobile ? '100%' : '20%';
|
|
|
|
|
}, [isMobile]);
|
|
|
|
|
|
|
|
|
|
let questionTypeComponent = null;
|
|
|
|
|
switch (question?.type) {
|
|
|
|
|
case 'TF':
|
|
|
|
|
questionTypeComponent = (
|
|
|
|
|
<TrueFalseQuestion
|
2024-04-16 12:14:20 -04:00
|
|
|
questionContent={question.stem}
|
2024-03-29 20:08:34 -04:00
|
|
|
correctAnswer={question.isTrue}
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
globalFeedback={question.globalFeedback?.text}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case 'MC':
|
|
|
|
|
questionTypeComponent = (
|
|
|
|
|
<MultipleChoiceQuestion
|
2024-09-15 21:41:24 -04:00
|
|
|
questionStem={question.stem}
|
2025-01-11 02:22:14 -05:00
|
|
|
choices={question.choices.map((choice, index) => ({ ...choice, id: index.toString() }))}
|
2024-03-29 20:08:34 -04:00
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
globalFeedback={question.globalFeedback?.text}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
case 'Numerical':
|
|
|
|
|
if (question.choices) {
|
|
|
|
|
if (!Array.isArray(question.choices)) {
|
|
|
|
|
questionTypeComponent = (
|
|
|
|
|
<NumericalQuestion
|
2024-04-16 12:14:20 -04:00
|
|
|
questionContent={question.stem}
|
2024-03-29 20:08:34 -04:00
|
|
|
correctAnswers={question.choices}
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
globalFeedback={question.globalFeedback?.text}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
questionTypeComponent = (
|
|
|
|
|
<NumericalQuestion
|
2024-04-16 12:14:20 -04:00
|
|
|
questionContent={question.stem}
|
2024-03-29 20:08:34 -04:00
|
|
|
correctAnswers={question.choices[0].text}
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
globalFeedback={question.globalFeedback?.text}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'Short':
|
|
|
|
|
questionTypeComponent = (
|
|
|
|
|
<ShortAnswerQuestion
|
2024-04-16 12:14:20 -04:00
|
|
|
questionContent={question.stem}
|
2025-01-11 02:22:14 -05:00
|
|
|
choices={question.choices.map((choice, index) => ({ ...choice, id: index.toString() }))}
|
2024-03-29 20:08:34 -04:00
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
|
|
|
showAnswer={showAnswer}
|
|
|
|
|
globalFeedback={question.globalFeedback?.text}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<div className="question-container">
|
|
|
|
|
{questionTypeComponent ? (
|
|
|
|
|
<>
|
|
|
|
|
{imageUrl && (
|
|
|
|
|
<img
|
|
|
|
|
src={imageUrl}
|
|
|
|
|
alt="QuestionImage"
|
|
|
|
|
style={{ width: imgWidth, marginBottom: '2rem' }}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{questionTypeComponent}
|
|
|
|
|
</>
|
|
|
|
|
) : (
|
|
|
|
|
<div>Question de type inconnue</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Question;
|