mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Compare commits
2 commits
fe44409e16
...
f8dd95f651
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8dd95f651 | ||
|
|
60ad2df67d |
11 changed files with 152 additions and 90 deletions
|
|
@ -21,7 +21,7 @@ describe('MultipleChoiceQuestionDisplay', () => {
|
||||||
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
||||||
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
||||||
|
|
||||||
const handleOnSubmitAnswer = (answer: string) => {
|
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||||
mockHandleOnSubmitAnswer(answer);
|
mockHandleOnSubmitAnswer(answer);
|
||||||
setShowAnswerState(true);
|
setShowAnswerState(true);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ describe('TrueFalseQuestion Component', () => {
|
||||||
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
||||||
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
||||||
|
|
||||||
const handleOnSubmitAnswer = (answer: boolean) => {
|
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||||
mockHandleSubmitAnswer(answer);
|
mockHandleSubmitAnswer(answer);
|
||||||
setShowAnswerState(true);
|
setShowAnswerState(true);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -7,37 +7,49 @@ import { MultipleChoiceQuestion } from 'gift-pegjs';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
question: MultipleChoiceQuestion;
|
question: MultipleChoiceQuestion;
|
||||||
handleOnSubmitAnswer?: (answer: string) => void;
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||||
showAnswer?: boolean;
|
showAnswer?: boolean;
|
||||||
|
passedAnswer?: string | number | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
const { question, showAnswer, handleOnSubmitAnswer } = props;
|
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } = props;
|
||||||
const [answer, setAnswer] = useState<string>();
|
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || ' ');
|
||||||
|
|
||||||
|
|
||||||
|
let disableButton = false;
|
||||||
|
if(handleOnSubmitAnswer === undefined){
|
||||||
|
disableButton = true;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAnswer(undefined);
|
if (passedAnswer !== undefined) {
|
||||||
}, [question]);
|
setAnswer(passedAnswer);
|
||||||
|
}
|
||||||
|
}, [passedAnswer]);
|
||||||
|
|
||||||
const handleOnClickAnswer = (choice: string) => {
|
const handleOnClickAnswer = (choice: string) => {
|
||||||
setAnswer(choice);
|
setAnswer(choice);
|
||||||
};
|
};
|
||||||
|
|
||||||
const alpha = Array.from(Array(26)).map((_e, i) => i + 65);
|
const alpha = Array.from(Array(26)).map((_e, i) => i + 65);
|
||||||
const alphabet = alpha.map((x) => String.fromCharCode(x));
|
const alphabet = alpha.map((x) => String.fromCharCode(x));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="question-container">
|
<div className="question-container">
|
||||||
<div className="question content">
|
<div className="question content">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
||||||
</div>
|
</div>
|
||||||
<div className="choices-wrapper mb-1">
|
<div className="choices-wrapper mb-1">
|
||||||
|
|
||||||
{question.choices.map((choice, i) => {
|
{question.choices.map((choice, i) => {
|
||||||
const selected = answer === choice.formattedText.text ? 'selected' : '';
|
const selected = answer === choice.formattedText.text ? 'selected' : '';
|
||||||
|
console.log("dsa", selected)
|
||||||
return (
|
return (
|
||||||
<div key={choice.formattedText.text + i} className="choice-container">
|
<div key={choice.formattedText.text + i} className="choice-container">
|
||||||
<Button
|
<Button
|
||||||
variant="text"
|
variant="text"
|
||||||
className="button-wrapper"
|
className="button-wrapper"
|
||||||
|
disabled={disableButton}
|
||||||
onClick={() => !showAnswer && handleOnClickAnswer(choice.formattedText.text)}>
|
onClick={() => !showAnswer && handleOnClickAnswer(choice.formattedText.text)}>
|
||||||
{showAnswer? (<div> {(choice.isCorrect ? '✅' : '❌')}</div>)
|
{showAnswer? (<div> {(choice.isCorrect ? '✅' : '❌')}</div>)
|
||||||
:``}
|
:``}
|
||||||
|
|
@ -67,9 +79,9 @@ const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
answer !== undefined && handleOnSubmitAnswer && handleOnSubmitAnswer(answer)
|
answer !== "" && handleOnSubmitAnswer && handleOnSubmitAnswer(answer)
|
||||||
}
|
}
|
||||||
disabled={answer === undefined}
|
disabled={answer === ''}
|
||||||
>
|
>
|
||||||
Répondre
|
Répondre
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// NumericalQuestion.tsx
|
// NumericalQuestion.tsx
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import '../questionStyle.css';
|
import '../questionStyle.css';
|
||||||
import { Button, TextField } from '@mui/material';
|
import { Button, TextField } from '@mui/material';
|
||||||
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
||||||
|
|
@ -8,19 +8,24 @@ import { isSimpleNumericalAnswer, isRangeNumericalAnswer, isHighLowNumericalAnsw
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
question: NumericalQuestion;
|
question: NumericalQuestion;
|
||||||
handleOnSubmitAnswer?: (answer: number) => void;
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||||
showAnswer?: boolean;
|
showAnswer?: boolean;
|
||||||
|
passedAnswer?: string | number | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const NumericalQuestionDisplay: React.FC<Props> = (props) => {
|
const NumericalQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
const { question, showAnswer, handleOnSubmitAnswer } =
|
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } =
|
||||||
props;
|
props;
|
||||||
|
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || '');
|
||||||
const [answer, setAnswer] = useState<number>();
|
|
||||||
|
|
||||||
const correctAnswers = question.choices;
|
const correctAnswers = question.choices;
|
||||||
let correctAnswer = '';
|
let correctAnswer = '';
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (passedAnswer !== null && passedAnswer !== undefined) {
|
||||||
|
setAnswer(passedAnswer);
|
||||||
|
}
|
||||||
|
}, [passedAnswer]);
|
||||||
|
|
||||||
//const isSingleAnswer = correctAnswers.length === 1;
|
//const isSingleAnswer = correctAnswers.length === 1;
|
||||||
|
|
||||||
if (isSimpleNumericalAnswer(correctAnswers[0])) {
|
if (isSimpleNumericalAnswer(correctAnswers[0])) {
|
||||||
|
|
@ -44,10 +49,16 @@ const NumericalQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
</div>
|
</div>
|
||||||
{showAnswer ? (
|
{showAnswer ? (
|
||||||
<>
|
<>
|
||||||
<div className="correct-answer-text mb-2">{correctAnswer}</div>
|
<div className="correct-answer-text mb-2">
|
||||||
|
<strong>La bonne réponse est: </strong>
|
||||||
|
{correctAnswer}</div>
|
||||||
|
<span>
|
||||||
|
<strong>Votre réponse est: </strong>{answer.toString()}
|
||||||
|
</span>
|
||||||
{question.formattedGlobalFeedback && <div className="global-feedback mb-2">
|
{question.formattedGlobalFeedback && <div className="global-feedback mb-2">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
||||||
</div>}
|
</div>}
|
||||||
|
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
|
@ -75,7 +86,7 @@ const NumericalQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
handleOnSubmitAnswer &&
|
handleOnSubmitAnswer &&
|
||||||
handleOnSubmitAnswer(answer)
|
handleOnSubmitAnswer(answer)
|
||||||
}
|
}
|
||||||
disabled={answer === undefined || isNaN(answer)}
|
disabled={answer === "" || isNaN(answer as number)}
|
||||||
>
|
>
|
||||||
Répondre
|
Répondre
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -11,11 +11,14 @@ interface QuestionProps {
|
||||||
question: Question;
|
question: Question;
|
||||||
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||||
showAnswer?: boolean;
|
showAnswer?: boolean;
|
||||||
|
answer?: string | number | boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
const QuestionDisplay: React.FC<QuestionProps> = ({
|
const QuestionDisplay: React.FC<QuestionProps> = ({
|
||||||
question,
|
question,
|
||||||
handleOnSubmitAnswer,
|
handleOnSubmitAnswer,
|
||||||
showAnswer,
|
showAnswer,
|
||||||
|
answer,
|
||||||
}) => {
|
}) => {
|
||||||
// const isMobile = useCheckMobileScreen();
|
// const isMobile = useCheckMobileScreen();
|
||||||
// const imgWidth = useMemo(() => {
|
// const imgWidth = useMemo(() => {
|
||||||
|
|
@ -30,37 +33,32 @@ const QuestionDisplay: React.FC<QuestionProps> = ({
|
||||||
question={question}
|
question={question}
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||||
showAnswer={showAnswer}
|
showAnswer={showAnswer}
|
||||||
|
passedAnswer={answer}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'MC':
|
case 'MC':
|
||||||
|
|
||||||
questionTypeComponent = (
|
questionTypeComponent = (
|
||||||
<MultipleChoiceQuestionDisplay
|
<MultipleChoiceQuestionDisplay
|
||||||
question={question}
|
question={question}
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||||
showAnswer={showAnswer}
|
showAnswer={showAnswer}
|
||||||
|
passedAnswer={answer}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'Numerical':
|
case 'Numerical':
|
||||||
if (question.choices) {
|
if (question.choices) {
|
||||||
if (!Array.isArray(question.choices)) {
|
|
||||||
questionTypeComponent = (
|
questionTypeComponent = (
|
||||||
<NumericalQuestionDisplay
|
<NumericalQuestionDisplay
|
||||||
question={question}
|
question={question}
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||||
showAnswer={showAnswer}
|
showAnswer={showAnswer}
|
||||||
|
passedAnswer={answer}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
questionTypeComponent = ( // TODO fix NumericalQuestion (correctAnswers is borked)
|
|
||||||
<NumericalQuestionDisplay
|
|
||||||
question={question}
|
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
|
||||||
showAnswer={showAnswer}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'Short':
|
case 'Short':
|
||||||
|
|
@ -69,6 +67,7 @@ const QuestionDisplay: React.FC<QuestionProps> = ({
|
||||||
question={question}
|
question={question}
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||||
showAnswer={showAnswer}
|
showAnswer={showAnswer}
|
||||||
|
passedAnswer={answer}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import '../questionStyle.css';
|
import '../questionStyle.css';
|
||||||
import { Button, TextField } from '@mui/material';
|
import { Button, TextField } from '@mui/material';
|
||||||
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
||||||
|
|
@ -6,14 +6,22 @@ import { ShortAnswerQuestion } from 'gift-pegjs';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
question: ShortAnswerQuestion;
|
question: ShortAnswerQuestion;
|
||||||
handleOnSubmitAnswer?: (answer: string) => void;
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||||
showAnswer?: boolean;
|
showAnswer?: boolean;
|
||||||
|
passedAnswer?: string | number | boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
const { question, showAnswer, handleOnSubmitAnswer } = props;
|
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } = props;
|
||||||
const [answer, setAnswer] = useState<string>();
|
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || ' ');
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (passedAnswer !== undefined) {
|
||||||
|
setAnswer(passedAnswer);
|
||||||
|
}
|
||||||
|
}, [passedAnswer]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="question-wrapper">
|
<div className="question-wrapper">
|
||||||
<div className="question content">
|
<div className="question content">
|
||||||
|
|
@ -22,11 +30,18 @@ const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
{showAnswer ? (
|
{showAnswer ? (
|
||||||
<>
|
<>
|
||||||
<div className="correct-answer-text mb-1">
|
<div className="correct-answer-text mb-1">
|
||||||
|
<span>
|
||||||
|
<strong>La bonne réponse est: </strong>
|
||||||
|
|
||||||
{question.choices.map((choice) => (
|
{question.choices.map((choice) => (
|
||||||
<div key={choice.text} className="mb-1">
|
<div key={choice.text} className="mb-1">
|
||||||
{choice.text}
|
{choice.text}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
<strong>Votre réponse est: </strong>{answer}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
{question.formattedGlobalFeedback && <div className="global-feedback mb-2">
|
{question.formattedGlobalFeedback && <div className="global-feedback mb-2">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
||||||
|
|
@ -54,7 +69,7 @@ const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
handleOnSubmitAnswer &&
|
handleOnSubmitAnswer &&
|
||||||
handleOnSubmitAnswer(answer)
|
handleOnSubmitAnswer(answer)
|
||||||
}
|
}
|
||||||
disabled={answer === undefined || answer === ''}
|
disabled={answer === null || answer === ''}
|
||||||
>
|
>
|
||||||
Répondre
|
Répondre
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// TrueFalseQuestion.tsx
|
// TrueFalseQuestion.tsx
|
||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState,useEffect } from 'react';
|
||||||
import '../questionStyle.css';
|
import '../questionStyle.css';
|
||||||
import { Button } from '@mui/material';
|
import { Button } from '@mui/material';
|
||||||
import { TrueFalseQuestion } from 'gift-pegjs';
|
import { TrueFalseQuestion } from 'gift-pegjs';
|
||||||
|
|
@ -7,18 +7,40 @@ import { FormattedTextTemplate } from 'src/components/GiftTemplate/templates/Tex
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
question: TrueFalseQuestion;
|
question: TrueFalseQuestion;
|
||||||
handleOnSubmitAnswer?: (answer: boolean) => void;
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||||
showAnswer?: boolean;
|
showAnswer?: boolean;
|
||||||
|
passedAnswer?: string | number | boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
const { question, showAnswer, handleOnSubmitAnswer } =
|
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer} =
|
||||||
props;
|
props;
|
||||||
const [answer, setAnswer] = useState<boolean | undefined>(undefined);
|
|
||||||
|
let disableButton = false;
|
||||||
|
if(handleOnSubmitAnswer === undefined){
|
||||||
|
disableButton = true;
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setAnswer(undefined);
|
if (passedAnswer === true || passedAnswer === false) {
|
||||||
}, [question]);
|
setAnswer(passedAnswer);
|
||||||
|
} else {
|
||||||
|
setAnswer(undefined);
|
||||||
|
}
|
||||||
|
}, [passedAnswer]);
|
||||||
|
|
||||||
|
const [answer, setAnswer] = useState<boolean | undefined>(() => {
|
||||||
|
|
||||||
|
if (passedAnswer === true || passedAnswer === false) {
|
||||||
|
return passedAnswer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
const handleOnClickAnswer = (choice: boolean) => {
|
||||||
|
setAnswer(choice);
|
||||||
|
};
|
||||||
|
|
||||||
const selectedTrue = answer ? 'selected' : '';
|
const selectedTrue = answer ? 'selected' : '';
|
||||||
const selectedFalse = answer !== undefined && !answer ? 'selected' : '';
|
const selectedFalse = answer !== undefined && !answer ? 'selected' : '';
|
||||||
|
|
@ -30,35 +52,38 @@ const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
<div className="choices-wrapper mb-1">
|
<div className="choices-wrapper mb-1">
|
||||||
<Button
|
<Button
|
||||||
className="button-wrapper"
|
className="button-wrapper"
|
||||||
onClick={() => !showAnswer && setAnswer(true)}
|
onClick={() => !showAnswer && handleOnClickAnswer(true)}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
disabled={disableButton}
|
||||||
>
|
>
|
||||||
{showAnswer? (<div> {(question.isTrue ? '✅' : '❌')}</div>):``}
|
{showAnswer? (<div> {(question.isTrue ? '✅' : '❌')}</div>):``}
|
||||||
<div className={`circle ${selectedTrue}`}>V</div>
|
<div className={`circle ${selectedTrue}`}>V</div>
|
||||||
<div className={`answer-text ${selectedTrue}`}>Vrai</div>
|
<div className={`answer-text ${selectedTrue}`}>Vrai</div>
|
||||||
|
|
||||||
|
{showAnswer && answer && question.trueFormattedFeedback && (
|
||||||
|
<div className="true-feedback mb-2">
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.trueFormattedFeedback) }} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
className="button-wrapper"
|
className="button-wrapper"
|
||||||
onClick={() => !showAnswer && setAnswer(false)}
|
onClick={() => !showAnswer && handleOnClickAnswer(false)}
|
||||||
fullWidth
|
fullWidth
|
||||||
|
disabled={disableButton}
|
||||||
|
|
||||||
>
|
>
|
||||||
{showAnswer? (<div> {(!question.isTrue ? '✅' : '❌')}</div>):``}
|
{showAnswer? (<div> {(!question.isTrue ? '✅' : '❌')}</div>):``}
|
||||||
<div className={`circle ${selectedFalse}`}>F</div>
|
<div className={`circle ${selectedFalse}`}>F</div>
|
||||||
<div className={`answer-text ${selectedFalse}`}>Faux</div>
|
<div className={`answer-text ${selectedFalse}`}>Faux</div>
|
||||||
|
|
||||||
|
{showAnswer && !answer && question.falseFormattedFeedback && (
|
||||||
|
<div className="false-feedback mb-2">
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.falseFormattedFeedback) }} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{/* selected TRUE, show True feedback if it exists */}
|
|
||||||
{showAnswer && answer && question.trueFormattedFeedback && (
|
|
||||||
<div className="true-feedback mb-2">
|
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.trueFormattedFeedback) }} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{/* selected FALSE, show False feedback if it exists */}
|
|
||||||
{showAnswer && !answer && question.falseFormattedFeedback && (
|
|
||||||
<div className="false-feedback mb-2">
|
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.falseFormattedFeedback) }} />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{question.formattedGlobalFeedback && showAnswer && (
|
{question.formattedGlobalFeedback && showAnswer && (
|
||||||
<div className="global-feedback mb-2">
|
<div className="global-feedback mb-2">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,25 @@
|
||||||
box-shadow: 0px 2px 5px hsl(0, 0%, 74%);
|
box-shadow: 0px 2px 5px hsl(0, 0%, 74%);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.true-feedback {
|
||||||
|
position: relative;
|
||||||
|
padding: 0 1rem;
|
||||||
|
background-color: hsl(43, 100%, 94%);
|
||||||
|
color: hsl(43, 95%, 9%);
|
||||||
|
border: hsl(36, 84%, 93%) 1px solid;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0px 2px 5px hsl(0, 0%, 74%);
|
||||||
|
}
|
||||||
|
.false-feedback {
|
||||||
|
position: relative;
|
||||||
|
padding: 0 1rem;
|
||||||
|
background-color: hsl(43, 100%, 94%);
|
||||||
|
color: hsl(43, 95%, 9%);
|
||||||
|
border: hsl(36, 84%, 93%) 1px solid;
|
||||||
|
border-radius: 6px;
|
||||||
|
box-shadow: 0px 2px 5px hsl(0, 0%, 74%);
|
||||||
|
}
|
||||||
|
|
||||||
.choices-wrapper {
|
.choices-wrapper {
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,8 @@ import React, { useEffect, useState } from 'react';
|
||||||
import QuestionComponent from '../QuestionsDisplay/QuestionDisplay';
|
import QuestionComponent from '../QuestionsDisplay/QuestionDisplay';
|
||||||
import '../../pages/Student/JoinRoom/joinRoom.css';
|
import '../../pages/Student/JoinRoom/joinRoom.css';
|
||||||
import { QuestionType } from '../../Types/QuestionType';
|
import { QuestionType } from '../../Types/QuestionType';
|
||||||
// import { QuestionService } from '../../services/QuestionService';
|
|
||||||
import { Button } from '@mui/material';
|
import { Button } from '@mui/material';
|
||||||
//import QuestionNavigation from '../QuestionNavigation/QuestionNavigation';
|
//import QuestionNavigation from '../QuestionNavigation/QuestionNavigation';
|
||||||
//import { ChevronLeft, ChevronRight } from '@mui/icons-material';
|
|
||||||
import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
||||||
import { Question } from 'gift-pegjs';
|
import { Question } from 'gift-pegjs';
|
||||||
|
|
||||||
|
|
@ -24,30 +22,24 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
||||||
//Ajouter type AnswerQuestionType en remplacement de QuestionType
|
//Ajouter type AnswerQuestionType en remplacement de QuestionType
|
||||||
const [questionInfos, setQuestion] = useState<QuestionType>(questions[0]);
|
const [questionInfos, setQuestion] = useState<QuestionType>(questions[0]);
|
||||||
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
||||||
// const [imageUrl, setImageUrl] = useState('');
|
const [answer, setAnswer] = useState<string | number | boolean>('');
|
||||||
|
|
||||||
|
|
||||||
const previousQuestion = () => {
|
const previousQuestion = () => {
|
||||||
setQuestion(questions[Number(questionInfos.question?.id) - 2]);
|
setQuestion(questions[Number(questionInfos.question?.id) - 2]);
|
||||||
setIsAnswerSubmitted(false);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const answer = localStorage.getItem(`Answer${questionInfos.question.id}`);
|
setAnswer(JSON.parse(localStorage.getItem(`Answer${questionInfos.question.id}`)||'null'));
|
||||||
if (answer !== null) {
|
if (answer !== null) {
|
||||||
setIsAnswerSubmitted(true);
|
setIsAnswerSubmitted(true);
|
||||||
} else {
|
} else {
|
||||||
setIsAnswerSubmitted(false);
|
setIsAnswerSubmitted(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
}, [questionInfos.question]);
|
}, [questionInfos.question , answer]);
|
||||||
|
|
||||||
const nextQuestion = () => {
|
const nextQuestion = () => {
|
||||||
setQuestion(questions[Number(questionInfos.question?.id)]);
|
setQuestion(questions[Number(questionInfos.question?.id)]);
|
||||||
setIsAnswerSubmitted(false);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||||
|
|
@ -81,6 +73,7 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||||
question={questionInfos.question as Question}
|
question={questionInfos.question as Question}
|
||||||
showAnswer={isAnswerSubmitted}
|
showAnswer={isAnswerSubmitted}
|
||||||
|
answer={answer}
|
||||||
/>
|
/>
|
||||||
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', marginTop: '1rem' }}>
|
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', marginTop: '1rem' }}>
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -20,39 +20,26 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
}) => {
|
}) => {
|
||||||
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
||||||
const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false);
|
const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false);
|
||||||
const [feedbackMessage, setFeedbackMessage] = useState<React.ReactNode>('');
|
const [answer, setAnswer] = useState<string | number | boolean>('');
|
||||||
|
|
||||||
|
|
||||||
const renderFeedbackMessage = (answer: string) => {
|
|
||||||
|
|
||||||
if(answer === 'true' || answer === 'false'){
|
|
||||||
return (<span>
|
|
||||||
<strong>Votre réponse est: </strong>{answer==="true" ? 'Vrai' : 'Faux'}
|
|
||||||
</span>)
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return (
|
|
||||||
<span>
|
|
||||||
<strong>Votre réponse est: </strong>{answer.toString()}
|
|
||||||
</span>
|
|
||||||
);}
|
|
||||||
};
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Close the feedback dialog when the question changes
|
// Close the feedback dialog when the question changes
|
||||||
handleFeedbackDialogClose();
|
handleFeedbackDialogClose();
|
||||||
setIsAnswerSubmitted(false);
|
setIsAnswerSubmitted(false);
|
||||||
const answer = localStorage.getItem(`Answer${questionInfos.question.id}`);
|
setAnswer(JSON.parse(localStorage.getItem(`Answer${questionInfos.question.id}`)||'null'));
|
||||||
if (answer !== null) {
|
if (typeof answer !== "object") {
|
||||||
setIsAnswerSubmitted(true);
|
setIsAnswerSubmitted(true);
|
||||||
setIsFeedbackDialogOpen(true);
|
setIsFeedbackDialogOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, [questionInfos.question]);
|
}, [questionInfos.question , answer]);
|
||||||
|
|
||||||
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||||
const idQuestion = Number(questionInfos.question.id) || -1;
|
const idQuestion = Number(questionInfos.question.id) || -1;
|
||||||
submitAnswer(answer, idQuestion);
|
submitAnswer(answer, idQuestion);
|
||||||
|
setAnswer(answer);
|
||||||
setFeedbackMessage(renderFeedbackMessage(answer.toString()));
|
|
||||||
setIsFeedbackDialogOpen(true);
|
setIsFeedbackDialogOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -85,6 +72,7 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
<QuestionComponent
|
<QuestionComponent
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||||
question={questionInfos.question as Question}
|
question={questionInfos.question as Question}
|
||||||
|
answer={answer}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
@ -100,7 +88,6 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
maxHeight: '400px',
|
maxHeight: '400px',
|
||||||
overflowY: 'auto',
|
overflowY: 'auto',
|
||||||
}}>
|
}}>
|
||||||
{feedbackMessage}
|
|
||||||
<div style={{ textAlign: 'left', fontWeight: 'bold', marginTop: '10px'}}
|
<div style={{ textAlign: 'left', fontWeight: 'bold', marginTop: '10px'}}
|
||||||
>Question : </div>
|
>Question : </div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -109,6 +96,8 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
||||||
question={questionInfos.question as Question}
|
question={questionInfos.question as Question}
|
||||||
showAnswer={true}
|
showAnswer={true}
|
||||||
|
answer={answer}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
|
|
|
||||||
|
|
@ -435,8 +435,6 @@ const ManageRoom: React.FC = () => {
|
||||||
message={`Êtes-vous sûr de vouloir quitter?`} />
|
message={`Êtes-vous sûr de vouloir quitter?`} />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div className='headerContent' style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', width: '100%' }}>
|
<div className='headerContent' style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', width: '100%' }}>
|
||||||
<div style={{ flex: 1, display: 'flex', justifyContent: 'center' }}>
|
<div style={{ flex: 1, display: 'flex', justifyContent: 'center' }}>
|
||||||
<div className='title'>Salle: {roomName}</div>
|
<div className='title'>Salle: {roomName}</div>
|
||||||
|
|
@ -485,6 +483,7 @@ const ManageRoom: React.FC = () => {
|
||||||
<QuestionDisplay
|
<QuestionDisplay
|
||||||
showAnswer={false}
|
showAnswer={false}
|
||||||
question={currentQuestion?.question as Question}
|
question={currentQuestion?.question as Question}
|
||||||
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue