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
8240de0a44
commit
fe44409e16
4 changed files with 53 additions and 36 deletions
|
|
@ -21,20 +21,33 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
||||||
submitAnswer,
|
submitAnswer,
|
||||||
disconnectWebSocket
|
disconnectWebSocket
|
||||||
}) => {
|
}) => {
|
||||||
|
//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 [imageUrl, setImageUrl] = useState('');
|
||||||
|
|
||||||
// const previousQuestion = () => {
|
const previousQuestion = () => {
|
||||||
// setQuestion(questions[Number(questionInfos.question?.id) - 2]);
|
setQuestion(questions[Number(questionInfos.question?.id) - 2]);
|
||||||
// setIsAnswerSubmitted(false);
|
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 = () => {
|
const nextQuestion = () => {
|
||||||
setQuestion(questions[Number(questionInfos.question?.id)]);
|
setQuestion(questions[Number(questionInfos.question?.id)]);
|
||||||
setIsAnswerSubmitted(false);
|
setIsAnswerSubmitted(false);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||||
|
|
@ -46,11 +59,13 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
||||||
return (
|
return (
|
||||||
<div className='room'>
|
<div className='room'>
|
||||||
<div className='roomHeader'>
|
<div className='roomHeader'>
|
||||||
|
|
||||||
<DisconnectButton
|
<DisconnectButton
|
||||||
onReturn={disconnectWebSocket}
|
onReturn={disconnectWebSocket}
|
||||||
message={`Êtes-vous sûr de vouloir quitter?`} />
|
message={`Êtes-vous sûr de vouloir quitter?`} />
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div >
|
||||||
|
<b>Question {questionInfos.question.id}/{questions.length}</b>
|
||||||
</div>
|
</div>
|
||||||
<div className="overflow-auto">
|
<div className="overflow-auto">
|
||||||
<div className="question-component-container">
|
<div className="question-component-container">
|
||||||
|
|
@ -67,24 +82,22 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
||||||
question={questionInfos.question as Question}
|
question={questionInfos.question as Question}
|
||||||
showAnswer={isAnswerSubmitted}
|
showAnswer={isAnswerSubmitted}
|
||||||
/>
|
/>
|
||||||
<div className="center-h-align mt-1/2">
|
<div style={{ display: 'flex', justifyContent: 'center', alignItems: 'center', marginTop: '1rem' }}>
|
||||||
<div className="w-12">
|
<div>
|
||||||
{/* <Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={previousQuestion}
|
onClick={previousQuestion}
|
||||||
fullWidth
|
fullWidth
|
||||||
startIcon={<ChevronLeft />}
|
|
||||||
disabled={Number(questionInfos.question.id) <= 1}
|
disabled={Number(questionInfos.question.id) <= 1}
|
||||||
>
|
>
|
||||||
Question précédente
|
Question précédente
|
||||||
</Button> */}
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<div className="w-12">
|
<div>
|
||||||
<Button style={{ display: isAnswerSubmitted ? 'block' : 'none' }}
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={nextQuestion}
|
onClick={nextQuestion}
|
||||||
fullWidth
|
fullWidth
|
||||||
//endIcon={<ChevronRight />}
|
|
||||||
disabled={Number(questionInfos.question.id) >= questions.length}
|
disabled={Number(questionInfos.question.id) >= questions.length}
|
||||||
>
|
>
|
||||||
Question suivante
|
Question suivante
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
// TeacherModeQuiz.tsx
|
// TeacherModeQuiz.tsx
|
||||||
import React, { useEffect, useState } from 'react';
|
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 DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
||||||
import { Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material';
|
import { Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material';
|
||||||
import { Question } from 'gift-pegjs';
|
import { Question } from 'gift-pegjs';
|
||||||
|
|
@ -43,12 +40,18 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
// 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}`);
|
||||||
|
if (answer !== null) {
|
||||||
|
setIsAnswerSubmitted(true);
|
||||||
|
setIsFeedbackDialogOpen(true);
|
||||||
|
}
|
||||||
|
|
||||||
}, [questionInfos.question]);
|
}, [questionInfos.question]);
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
setFeedbackMessage(renderFeedbackMessage(answer.toString()));
|
setFeedbackMessage(renderFeedbackMessage(answer.toString()));
|
||||||
setIsFeedbackDialogOpen(true);
|
setIsFeedbackDialogOpen(true);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ const JoinRoom: React.FC = () => {
|
||||||
socket.on('next-question', (question: QuestionType) => {
|
socket.on('next-question', (question: QuestionType) => {
|
||||||
setQuizMode('teacher');
|
setQuizMode('teacher');
|
||||||
setIsWaitingForTeacher(false);
|
setIsWaitingForTeacher(false);
|
||||||
|
|
||||||
setQuestion(question);
|
setQuestion(question);
|
||||||
});
|
});
|
||||||
socket.on('launch-student-mode', (questions: QuestionType[]) => {
|
socket.on('launch-student-mode', (questions: QuestionType[]) => {
|
||||||
|
|
@ -78,6 +79,7 @@ const JoinRoom: React.FC = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const disconnect = () => {
|
const disconnect = () => {
|
||||||
|
localStorage.clear();
|
||||||
webSocketService.disconnect();
|
webSocketService.disconnect();
|
||||||
setSocket(null);
|
setSocket(null);
|
||||||
setQuestion(undefined);
|
setQuestion(undefined);
|
||||||
|
|
@ -107,7 +109,7 @@ const JoinRoom: React.FC = () => {
|
||||||
username: username,
|
username: username,
|
||||||
idQuestion: idQuestion
|
idQuestion: idQuestion
|
||||||
};
|
};
|
||||||
|
localStorage.setItem(`Answer${idQuestion}`, JSON.stringify(answer));
|
||||||
webSocketService.submitAnswer(answerData);
|
webSocketService.submitAnswer(answerData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,6 @@ const setupWebsocket = (io) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on("next-question", ({ roomName, question }) => {
|
socket.on("next-question", ({ roomName, question }) => {
|
||||||
// console.log("next-question", roomName, question);
|
|
||||||
socket.to(roomName).emit("next-question", question);
|
socket.to(roomName).emit("next-question", question);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue