From fe44409e16b12e588dab5b22a4e62e3d6d42241c Mon Sep 17 00:00:00 2001 From: JubaAzul <118773284+JubaAzul@users.noreply.github.com> Date: Mon, 3 Mar 2025 17:00:42 -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 --- .../StudentModeQuiz/StudentModeQuiz.tsx | 71 +++++++++++-------- .../TeacherModeQuiz/TeacherModeQuiz.tsx | 13 ++-- .../src/pages/Student/JoinRoom/JoinRoom.tsx | 4 +- server/socket/socket.js | 1 - 4 files changed, 53 insertions(+), 36 deletions(-) diff --git a/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx b/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx index eb70432..137c872 100644 --- a/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx +++ b/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx @@ -21,20 +21,33 @@ const StudentModeQuiz: React.FC = ({ submitAnswer, disconnectWebSocket }) => { + //Ajouter type AnswerQuestionType en remplacement de QuestionType const [questionInfos, setQuestion] = useState(questions[0]); const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false); // const [imageUrl, setImageUrl] = useState(''); - // const previousQuestion = () => { - // setQuestion(questions[Number(questionInfos.question?.id) - 2]); - // setIsAnswerSubmitted(false); - // }; + const previousQuestion = () => { + setQuestion(questions[Number(questionInfos.question?.id) - 2]); + setIsAnswerSubmitted(false); + + }; - useEffect(() => {}, [questionInfos]); + + + useEffect(() => { + const answer = localStorage.getItem(`Answer${questionInfos.question.id}`); + if (answer !== null) { + setIsAnswerSubmitted(true); + } else { + setIsAnswerSubmitted(false); + + } + }, [questionInfos.question]); const nextQuestion = () => { setQuestion(questions[Number(questionInfos.question?.id)]); setIsAnswerSubmitted(false); + }; const handleOnSubmitAnswer = (answer: string | number | boolean) => { @@ -46,11 +59,13 @@ const StudentModeQuiz: React.FC = ({ return (
- +
+
+ Question {questionInfos.question.id}/{questions.length}
@@ -67,30 +82,28 @@ const StudentModeQuiz: React.FC = ({ question={questionInfos.question as Question} showAnswer={isAnswerSubmitted} /> -
-
- {/* */} -
-
- -
+
+
+
+
+ +
+
diff --git a/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx b/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx index 3188211..c28e708 100644 --- a/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx +++ b/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx @@ -1,11 +1,8 @@ // TeacherModeQuiz.tsx 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 DisconnectButton from 'src/components/DisconnectButton/DisconnectButton'; import { Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material'; import { Question } from 'gift-pegjs'; @@ -24,7 +21,7 @@ const TeacherModeQuiz: React.FC = ({ const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false); const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false); const [feedbackMessage, setFeedbackMessage] = useState(''); - + const renderFeedbackMessage = (answer: string) => { if(answer === 'true' || answer === 'false'){ @@ -43,12 +40,18 @@ const TeacherModeQuiz: React.FC = ({ // Close the feedback dialog when the question changes handleFeedbackDialogClose(); setIsAnswerSubmitted(false); - + const answer = localStorage.getItem(`Answer${questionInfos.question.id}`); + if (answer !== null) { + setIsAnswerSubmitted(true); + setIsFeedbackDialogOpen(true); + } + }, [questionInfos.question]); const handleOnSubmitAnswer = (answer: string | number | boolean) => { const idQuestion = Number(questionInfos.question.id) || -1; submitAnswer(answer, idQuestion); + setFeedbackMessage(renderFeedbackMessage(answer.toString())); setIsFeedbackDialogOpen(true); }; diff --git a/client/src/pages/Student/JoinRoom/JoinRoom.tsx b/client/src/pages/Student/JoinRoom/JoinRoom.tsx index f0ac8d7..94ffced 100644 --- a/client/src/pages/Student/JoinRoom/JoinRoom.tsx +++ b/client/src/pages/Student/JoinRoom/JoinRoom.tsx @@ -45,6 +45,7 @@ const JoinRoom: React.FC = () => { socket.on('next-question', (question: QuestionType) => { setQuizMode('teacher'); setIsWaitingForTeacher(false); + setQuestion(question); }); socket.on('launch-student-mode', (questions: QuestionType[]) => { @@ -78,6 +79,7 @@ const JoinRoom: React.FC = () => { }; const disconnect = () => { + localStorage.clear(); webSocketService.disconnect(); setSocket(null); setQuestion(undefined); @@ -107,7 +109,7 @@ const JoinRoom: React.FC = () => { username: username, idQuestion: idQuestion }; - + localStorage.setItem(`Answer${idQuestion}`, JSON.stringify(answer)); webSocketService.submitAnswer(answerData); }; diff --git a/server/socket/socket.js b/server/socket/socket.js index fc21632..13f882c 100644 --- a/server/socket/socket.js +++ b/server/socket/socket.js @@ -68,7 +68,6 @@ const setupWebsocket = (io) => { }); socket.on("next-question", ({ roomName, question }) => { - // console.log("next-question", roomName, question); socket.to(roomName).emit("next-question", question); });