From f8dd95f65196150878daeb759f15fd8f1bba658c Mon Sep 17 00:00:00 2001 From: JubaAzul <118773284+JubaAzul@users.noreply.github.com> Date: Fri, 7 Mar 2025 11:36:43 -0500 Subject: [PATCH] =?UTF-8?q?R=C3=A9ponse=20=C3=A0=20une=20question=20non=20?= =?UTF-8?q?enregistr=C3=A9e=20lorsque=20=C3=89tudiant=20reviens=20en=20arr?= =?UTF-8?q?i=C3=A8re=20dans=20le=20quiz=20Fixes=20#200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MultipleChoiceQuestionDisplay.test.tsx | 2 +- .../TrueFalseQuestionDisplay.test.tsx | 2 +- .../MultipleChoiceQuestionDisplay.tsx | 23 +++++++-- .../NumericalQuestionDisplay.tsx | 27 +++++++--- .../QuestionsDisplay/QuestionDisplay.tsx | 15 ++---- .../ShortAnswerQuestionDisplay.tsx | 27 +++++++--- .../TrueFalseQuestionDisplay.tsx | 51 ++++++++++++------- .../QuestionsDisplay/questionStyle.css | 19 +++++++ .../StudentModeQuiz/StudentModeQuiz.tsx | 18 +++---- .../TeacherModeQuiz/TeacherModeQuiz.tsx | 20 +------- .../pages/Teacher/ManageRoom/ManageRoom.tsx | 3 +- 11 files changed, 126 insertions(+), 81 deletions(-) diff --git a/client/src/__tests__/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx b/client/src/__tests__/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx index 05900fc..018d96d 100644 --- a/client/src/__tests__/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx +++ b/client/src/__tests__/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.test.tsx @@ -21,7 +21,7 @@ describe('MultipleChoiceQuestionDisplay', () => { const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => { const [showAnswerState, setShowAnswerState] = useState(showAnswer); - const handleOnSubmitAnswer = (answer: string) => { + const handleOnSubmitAnswer = (answer: string | number | boolean) => { mockHandleOnSubmitAnswer(answer); setShowAnswerState(true); }; diff --git a/client/src/__tests__/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.test.tsx b/client/src/__tests__/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.test.tsx index 5bcb7df..f640710 100644 --- a/client/src/__tests__/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.test.tsx +++ b/client/src/__tests__/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.test.tsx @@ -16,7 +16,7 @@ describe('TrueFalseQuestion Component', () => { const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => { const [showAnswerState, setShowAnswerState] = useState(showAnswer); - const handleOnSubmitAnswer = (answer: boolean) => { + const handleOnSubmitAnswer = (answer: string | number | boolean) => { mockHandleSubmitAnswer(answer); setShowAnswerState(true); }; diff --git a/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx index 790848f..c8e8f69 100644 --- a/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx @@ -1,5 +1,5 @@ // MultipleChoiceQuestionDisplay.tsx -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import '../questionStyle.css'; import { Button } from '@mui/material'; import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate'; @@ -14,29 +14,42 @@ interface Props { const MultipleChoiceQuestionDisplay: React.FC = (props) => { const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } = props; - const [answer, setAnswer] = useState(passedAnswer || ''); - + const [answer, setAnswer] = useState(passedAnswer || ' '); + + + let disableButton = false; + if(handleOnSubmitAnswer === undefined){ + disableButton = true; + } + + useEffect(() => { + if (passedAnswer !== undefined) { + setAnswer(passedAnswer); + } + }, [passedAnswer]); const handleOnClickAnswer = (choice: string) => { setAnswer(choice); }; - - const alpha = Array.from(Array(26)).map((_e, i) => i + 65); const alphabet = alpha.map((x) => String.fromCharCode(x)); + return (
+ {question.choices.map((choice, i) => { const selected = answer === choice.formattedText.text ? 'selected' : ''; + console.log("dsa", selected) return (
{showAnswer ? ( <> -
{correctAnswer}
+
+ La bonne réponse est: + {correctAnswer}
+ + Votre réponse est: {answer.toString()} + {question.formattedGlobalFeedback &&
} + ) : ( <> @@ -75,7 +86,7 @@ const NumericalQuestionDisplay: React.FC = (props) => { handleOnSubmitAnswer && handleOnSubmitAnswer(answer) } - disabled={answer === undefined || isNaN(answer)} + disabled={answer === "" || isNaN(answer as number)} > Répondre diff --git a/client/src/components/QuestionsDisplay/QuestionDisplay.tsx b/client/src/components/QuestionsDisplay/QuestionDisplay.tsx index 4ec3312..a1f0f30 100644 --- a/client/src/components/QuestionsDisplay/QuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/QuestionDisplay.tsx @@ -12,6 +12,7 @@ interface QuestionProps { handleOnSubmitAnswer?: (answer: string | number | boolean) => void; showAnswer?: boolean; answer?: string | number | boolean; + } const QuestionDisplay: React.FC = ({ question, @@ -37,6 +38,7 @@ const QuestionDisplay: React.FC = ({ ); break; case 'MC': + questionTypeComponent = ( = ({ break; case 'Numerical': if (question.choices) { - if (!Array.isArray(question.choices)) { questionTypeComponent = ( ); - } else { - questionTypeComponent = ( // TODO fix NumericalQuestion (correctAnswers is borked) - - ); - } } break; case 'Short': @@ -73,6 +67,7 @@ const QuestionDisplay: React.FC = ({ question={question} handleOnSubmitAnswer={handleOnSubmitAnswer} showAnswer={showAnswer} + passedAnswer={answer} /> ); break; diff --git a/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx index 50c2261..f415679 100644 --- a/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import '../questionStyle.css'; import { Button, TextField } from '@mui/material'; import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate'; @@ -6,14 +6,22 @@ import { ShortAnswerQuestion } from 'gift-pegjs'; interface Props { question: ShortAnswerQuestion; - handleOnSubmitAnswer?: (answer: string) => void; + handleOnSubmitAnswer?: (answer: string | number | boolean) => void; showAnswer?: boolean; + passedAnswer?: string | number | boolean; + } const ShortAnswerQuestionDisplay: React.FC = (props) => { - const { question, showAnswer, handleOnSubmitAnswer } = props; - const [answer, setAnswer] = useState(); - + const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } = props; + const [answer, setAnswer] = useState(passedAnswer || ' '); + + useEffect(() => { + if (passedAnswer !== undefined) { + setAnswer(passedAnswer); + } + }, [passedAnswer]); + return (
@@ -22,11 +30,18 @@ const ShortAnswerQuestionDisplay: React.FC = (props) => { {showAnswer ? ( <>
+ + La bonne réponse est: + {question.choices.map((choice) => (
{choice.text}
))} +
+ + Votre réponse est: {answer} +
{question.formattedGlobalFeedback &&
@@ -54,7 +69,7 @@ const ShortAnswerQuestionDisplay: React.FC = (props) => { handleOnSubmitAnswer && handleOnSubmitAnswer(answer) } - disabled={answer === undefined || answer === ''} + disabled={answer === null || answer === ''} > Répondre diff --git a/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx index 3adc3b8..599888b 100644 --- a/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx @@ -1,14 +1,13 @@ // TrueFalseQuestion.tsx -import React, { useState } from 'react'; +import React, { useState,useEffect } from 'react'; import '../questionStyle.css'; import { Button } from '@mui/material'; import { TrueFalseQuestion } from 'gift-pegjs'; import { FormattedTextTemplate } from 'src/components/GiftTemplate/templates/TextTypeTemplate'; -import { Answer } from 'src/Types/StudentType'; interface Props { question: TrueFalseQuestion; - handleOnSubmitAnswer?: (answer: Answer) => void; + handleOnSubmitAnswer?: (answer: string | number | boolean) => void; showAnswer?: boolean; passedAnswer?: string | number | boolean; } @@ -16,12 +15,26 @@ interface Props { const TrueFalseQuestionDisplay: React.FC = (props) => { const { question, showAnswer, handleOnSubmitAnswer, passedAnswer} = 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(() => { - if (typeof passedAnswer === 'boolean') { + + if (passedAnswer === true || passedAnswer === false) { return passedAnswer; } + return undefined; }); @@ -29,7 +42,6 @@ const TrueFalseQuestionDisplay: React.FC = (props) => { setAnswer(choice); }; - console.log("Answer", answer); const selectedTrue = answer ? 'selected' : ''; const selectedFalse = answer !== undefined && !answer ? 'selected' : ''; return ( @@ -42,33 +54,36 @@ const TrueFalseQuestionDisplay: React.FC = (props) => { className="button-wrapper" onClick={() => !showAnswer && handleOnClickAnswer(true)} fullWidth + disabled={disableButton} > {showAnswer? (
{(question.isTrue ? '✅' : '❌')}
):``}
V
Vrai
+ + {showAnswer && answer && question.trueFormattedFeedback && ( +
+
+
+ )}
- {/* selected TRUE, show True feedback if it exists */} - {showAnswer && answer && question.trueFormattedFeedback && ( -
-
-
- )} - {/* selected FALSE, show False feedback if it exists */} - {showAnswer && !answer && question.falseFormattedFeedback && ( -
-
-
- )} {question.formattedGlobalFeedback && showAnswer && (
diff --git a/client/src/components/QuestionsDisplay/questionStyle.css b/client/src/components/QuestionsDisplay/questionStyle.css index cdf611f..f300ba2 100644 --- a/client/src/components/QuestionsDisplay/questionStyle.css +++ b/client/src/components/QuestionsDisplay/questionStyle.css @@ -147,6 +147,25 @@ 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 { width: 90%; } diff --git a/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx b/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx index 4af330e..d10411f 100644 --- a/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx +++ b/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx @@ -3,10 +3,8 @@ import React, { useEffect, useState } from 'react'; import QuestionComponent from '../QuestionsDisplay/QuestionDisplay'; import '../../pages/Student/JoinRoom/joinRoom.css'; import { QuestionType } from '../../Types/QuestionType'; -// import { QuestionService } from '../../services/QuestionService'; import { Button } from '@mui/material'; //import QuestionNavigation from '../QuestionNavigation/QuestionNavigation'; -//import { ChevronLeft, ChevronRight } from '@mui/icons-material'; import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton'; import { Question } from 'gift-pegjs'; @@ -24,28 +22,24 @@ const StudentModeQuiz: React.FC = ({ //Ajouter type AnswerQuestionType en remplacement de QuestionType const [questionInfos, setQuestion] = useState(questions[0]); const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false); - // const [imageUrl, setImageUrl] = useState(''); + const [answer, setAnswer] = useState(''); + const previousQuestion = () => { - setQuestion(questions[Number(questionInfos.question?.id) - 2]); - setIsAnswerSubmitted(false); - + setQuestion(questions[Number(questionInfos.question?.id) - 2]); }; useEffect(() => { - const answer = localStorage.getItem(`Answer${questionInfos.question.id}`); + setAnswer(JSON.parse(localStorage.getItem(`Answer${questionInfos.question.id}`)||'null')); if (answer !== null) { setIsAnswerSubmitted(true); } else { setIsAnswerSubmitted(false); - } - }, [questionInfos.question]); + }, [questionInfos.question , answer]); const nextQuestion = () => { setQuestion(questions[Number(questionInfos.question?.id)]); - setIsAnswerSubmitted(false); - }; const handleOnSubmitAnswer = (answer: string | number | boolean) => { @@ -79,7 +73,7 @@ const StudentModeQuiz: React.FC = ({ handleOnSubmitAnswer={handleOnSubmitAnswer} question={questionInfos.question as Question} showAnswer={isAnswerSubmitted} - answer={localStorage.getItem(`Answer${questionInfos.question.id}`) || undefined} + answer={answer} />
diff --git a/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx b/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx index 9ee0537..456b227 100644 --- a/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx +++ b/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx @@ -20,30 +20,16 @@ const TeacherModeQuiz: React.FC = ({ }) => { const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false); const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false); - const [feedbackMessage, setFeedbackMessage] = useState(''); const [answer, setAnswer] = useState(''); - const renderFeedbackMessage = (answer: string) => { - if(answer === 'true' || answer === 'false'){ - return ( - Votre réponse est: {answer==="true" ? 'Vrai' : 'Faux'} - ) - } - else{ - return ( - - Votre réponse est: {answer.toString()} - - );} - }; useEffect(() => { // Close the feedback dialog when the question changes handleFeedbackDialogClose(); setIsAnswerSubmitted(false); setAnswer(JSON.parse(localStorage.getItem(`Answer${questionInfos.question.id}`)||'null')); - if (answer) { + if (typeof answer !== "object") { setIsAnswerSubmitted(true); setIsFeedbackDialogOpen(true); } @@ -53,8 +39,7 @@ const TeacherModeQuiz: React.FC = ({ const handleOnSubmitAnswer = (answer: string | number | boolean) => { const idQuestion = Number(questionInfos.question.id) || -1; submitAnswer(answer, idQuestion); - - setFeedbackMessage(renderFeedbackMessage(answer.toString())); + setAnswer(answer); setIsFeedbackDialogOpen(true); }; @@ -103,7 +88,6 @@ const TeacherModeQuiz: React.FC = ({ maxHeight: '400px', overflowY: 'auto', }}> - {feedbackMessage}
Question :
diff --git a/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx b/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx index 7af12f9..f63b60a 100644 --- a/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx +++ b/client/src/pages/Teacher/ManageRoom/ManageRoom.tsx @@ -435,8 +435,6 @@ const ManageRoom: React.FC = () => { message={`Êtes-vous sûr de vouloir quitter?`} /> - -
Salle: {roomName}
@@ -485,6 +483,7 @@ const ManageRoom: React.FC = () => { )}