mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Réponse à une question non enregistrée lorsque Étudiant reviens en arrière dans le quiz
Fixes #200
This commit is contained in:
parent
60ad2df67d
commit
f8dd95f651
11 changed files with 126 additions and 81 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);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
// MultipleChoiceQuestionDisplay.tsx
|
// MultipleChoiceQuestionDisplay.tsx
|
||||||
import React, { useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import '../questionStyle.css';
|
import '../questionStyle.css';
|
||||||
import { Button } from '@mui/material';
|
import { Button } from '@mui/material';
|
||||||
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
||||||
|
|
@ -17,26 +17,39 @@ const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || ' ');
|
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || ' ');
|
||||||
|
|
||||||
|
|
||||||
|
let disableButton = false;
|
||||||
|
if(handleOnSubmitAnswer === undefined){
|
||||||
|
disableButton = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (passedAnswer !== undefined) {
|
||||||
|
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>)
|
||||||
:``}
|
:``}
|
||||||
|
|
|
||||||
|
|
@ -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>
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ interface QuestionProps {
|
||||||
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||||
showAnswer?: boolean;
|
showAnswer?: boolean;
|
||||||
answer?: string | number | boolean;
|
answer?: string | number | boolean;
|
||||||
|
|
||||||
}
|
}
|
||||||
const QuestionDisplay: React.FC<QuestionProps> = ({
|
const QuestionDisplay: React.FC<QuestionProps> = ({
|
||||||
question,
|
question,
|
||||||
|
|
@ -37,6 +38,7 @@ const QuestionDisplay: React.FC<QuestionProps> = ({
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case 'MC':
|
case 'MC':
|
||||||
|
|
||||||
questionTypeComponent = (
|
questionTypeComponent = (
|
||||||
<MultipleChoiceQuestionDisplay
|
<MultipleChoiceQuestionDisplay
|
||||||
question={question}
|
question={question}
|
||||||
|
|
@ -48,23 +50,15 @@ const QuestionDisplay: React.FC<QuestionProps> = ({
|
||||||
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':
|
||||||
|
|
@ -73,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,13 +6,21 @@ 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">
|
||||||
|
|
@ -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,14 +1,13 @@
|
||||||
// TrueFalseQuestion.tsx
|
// TrueFalseQuestion.tsx
|
||||||
import React, { useState } 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';
|
||||||
import { FormattedTextTemplate } from 'src/components/GiftTemplate/templates/TextTypeTemplate';
|
import { FormattedTextTemplate } from 'src/components/GiftTemplate/templates/TextTypeTemplate';
|
||||||
import { Answer } from 'src/Types/StudentType';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
question: TrueFalseQuestion;
|
question: TrueFalseQuestion;
|
||||||
handleOnSubmitAnswer?: (answer: Answer) => void;
|
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||||
showAnswer?: boolean;
|
showAnswer?: boolean;
|
||||||
passedAnswer?: string | number | boolean;
|
passedAnswer?: string | number | boolean;
|
||||||
}
|
}
|
||||||
|
|
@ -16,12 +15,26 @@ interface Props {
|
||||||
const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer} =
|
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer} =
|
||||||
props;
|
props;
|
||||||
console.log("Passedanswer", passedAnswer);
|
|
||||||
|
let disableButton = false;
|
||||||
|
if(handleOnSubmitAnswer === undefined){
|
||||||
|
disableButton = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (passedAnswer === true || passedAnswer === false) {
|
||||||
|
setAnswer(passedAnswer);
|
||||||
|
} else {
|
||||||
|
setAnswer(undefined);
|
||||||
|
}
|
||||||
|
}, [passedAnswer]);
|
||||||
|
|
||||||
const [answer, setAnswer] = useState<boolean | undefined>(() => {
|
const [answer, setAnswer] = useState<boolean | undefined>(() => {
|
||||||
if (typeof passedAnswer === 'boolean') {
|
|
||||||
|
if (passedAnswer === true || passedAnswer === false) {
|
||||||
return passedAnswer;
|
return passedAnswer;
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -29,7 +42,6 @@ const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
setAnswer(choice);
|
setAnswer(choice);
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("Answer", answer);
|
|
||||||
const selectedTrue = answer ? 'selected' : '';
|
const selectedTrue = answer ? 'selected' : '';
|
||||||
const selectedFalse = answer !== undefined && !answer ? 'selected' : '';
|
const selectedFalse = answer !== undefined && !answer ? 'selected' : '';
|
||||||
return (
|
return (
|
||||||
|
|
@ -42,33 +54,36 @@ const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
||||||
className="button-wrapper"
|
className="button-wrapper"
|
||||||
onClick={() => !showAnswer && handleOnClickAnswer(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>
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
className="button-wrapper"
|
|
||||||
onClick={() => !showAnswer && handleOnClickAnswer(false)}
|
|
||||||
fullWidth
|
|
||||||
>
|
|
||||||
{showAnswer? (<div> {(!question.isTrue ? '✅' : '❌')}</div>):``}
|
|
||||||
<div className={`circle ${selectedFalse}`}>F</div>
|
|
||||||
<div className={`answer-text ${selectedFalse}`}>Faux</div>
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
{/* selected TRUE, show True feedback if it exists */}
|
|
||||||
{showAnswer && answer && question.trueFormattedFeedback && (
|
{showAnswer && answer && question.trueFormattedFeedback && (
|
||||||
<div className="true-feedback mb-2">
|
<div className="true-feedback mb-2">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.trueFormattedFeedback) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.trueFormattedFeedback) }} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{/* selected FALSE, show False feedback if it exists */}
|
</Button>
|
||||||
|
<Button
|
||||||
|
className="button-wrapper"
|
||||||
|
onClick={() => !showAnswer && handleOnClickAnswer(false)}
|
||||||
|
fullWidth
|
||||||
|
disabled={disableButton}
|
||||||
|
|
||||||
|
>
|
||||||
|
{showAnswer? (<div> {(!question.isTrue ? '✅' : '❌')}</div>):``}
|
||||||
|
<div className={`circle ${selectedFalse}`}>F</div>
|
||||||
|
<div className={`answer-text ${selectedFalse}`}>Faux</div>
|
||||||
|
|
||||||
{showAnswer && !answer && question.falseFormattedFeedback && (
|
{showAnswer && !answer && question.falseFormattedFeedback && (
|
||||||
<div className="false-feedback mb-2">
|
<div className="false-feedback mb-2">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.falseFormattedFeedback) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.falseFormattedFeedback) }} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
</Button>
|
||||||
|
</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,28 +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) => {
|
||||||
|
|
@ -79,7 +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={localStorage.getItem(`Answer${questionInfos.question.id}`) || undefined}
|
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,30 +20,16 @@ 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 [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);
|
||||||
setAnswer(JSON.parse(localStorage.getItem(`Answer${questionInfos.question.id}`)||'null'));
|
setAnswer(JSON.parse(localStorage.getItem(`Answer${questionInfos.question.id}`)||'null'));
|
||||||
if (answer) {
|
if (typeof answer !== "object") {
|
||||||
setIsAnswerSubmitted(true);
|
setIsAnswerSubmitted(true);
|
||||||
setIsFeedbackDialogOpen(true);
|
setIsFeedbackDialogOpen(true);
|
||||||
}
|
}
|
||||||
|
|
@ -53,8 +39,7 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -103,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>
|
||||||
|
|
|
||||||
|
|
@ -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