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); });