2024-03-29 20:08:34 -04:00
|
|
|
// TeacherModeQuiz.tsx
|
|
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
|
2025-01-25 02:02:18 -05:00
|
|
|
import QuestionComponent from '../QuestionsDisplay/QuestionDisplay';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
import '../../pages/Student/JoinRoom/joinRoom.css';
|
|
|
|
|
import { QuestionType } from '../../Types/QuestionType';
|
2024-09-15 00:34:41 -04:00
|
|
|
// import { QuestionService } from '../../services/QuestionService';
|
2025-01-16 12:37:07 -05:00
|
|
|
import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
2024-09-24 19:56:47 -04:00
|
|
|
import { Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material';
|
2025-01-25 02:02:18 -05:00
|
|
|
import { Question } from 'gift-pegjs';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
interface TeacherModeQuizProps {
|
|
|
|
|
questionInfos: QuestionType;
|
2024-09-26 00:34:30 -04:00
|
|
|
submitAnswer: (answer: string | number | boolean, idQuestion: number) => void;
|
2024-03-29 20:08:34 -04:00
|
|
|
disconnectWebSocket: () => void;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
|
|
|
|
questionInfos,
|
|
|
|
|
submitAnswer,
|
|
|
|
|
disconnectWebSocket
|
|
|
|
|
}) => {
|
|
|
|
|
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
2024-09-24 19:56:47 -04:00
|
|
|
const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false);
|
|
|
|
|
const [feedbackMessage, setFeedbackMessage] = useState('');
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-02-05 19:45:55 -05:00
|
|
|
// Close the feedback dialog when the question changes
|
|
|
|
|
handleFeedbackDialogClose();
|
2024-03-29 20:08:34 -04:00
|
|
|
setIsAnswerSubmitted(false);
|
2025-02-05 19:45:55 -05:00
|
|
|
|
|
|
|
|
}, [questionInfos.question]);
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
2024-09-26 00:34:30 -04:00
|
|
|
const idQuestion = Number(questionInfos.question.id) || -1;
|
2024-03-29 20:08:34 -04:00
|
|
|
submitAnswer(answer, idQuestion);
|
2024-09-24 19:56:47 -04:00
|
|
|
setFeedbackMessage(`Votre réponse est "${answer.toString()}".`);
|
|
|
|
|
setIsFeedbackDialogOpen(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleFeedbackDialogClose = () => {
|
|
|
|
|
setIsFeedbackDialogOpen(false);
|
2024-03-29 20:08:34 -04:00
|
|
|
setIsAnswerSubmitted(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='room'>
|
|
|
|
|
<div className='roomHeader'>
|
|
|
|
|
|
|
|
|
|
<DisconnectButton
|
|
|
|
|
onReturn={disconnectWebSocket}
|
|
|
|
|
message={`Êtes-vous sûr de vouloir quitter?`} />
|
|
|
|
|
|
|
|
|
|
<div className='centerTitle'>
|
|
|
|
|
<div className='title'>Question {questionInfos.question.id}</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div className='dumb'></div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{isAnswerSubmitted ? (
|
2024-09-24 19:56:47 -04:00
|
|
|
<div>
|
|
|
|
|
En attente pour la prochaine question...
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<QuestionComponent
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
2025-01-25 02:02:18 -05:00
|
|
|
question={questionInfos.question as Question}
|
2024-09-24 19:56:47 -04:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<Dialog
|
|
|
|
|
open={isFeedbackDialogOpen}
|
|
|
|
|
onClose={handleFeedbackDialogClose}
|
|
|
|
|
>
|
|
|
|
|
<DialogTitle>Rétroaction</DialogTitle>
|
|
|
|
|
<DialogContent>
|
|
|
|
|
{feedbackMessage}
|
|
|
|
|
<QuestionComponent
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
2025-01-25 02:02:18 -05:00
|
|
|
question={questionInfos.question as Question}
|
2024-09-24 19:56:47 -04:00
|
|
|
showAnswer={true}
|
2024-03-29 20:08:34 -04:00
|
|
|
/>
|
2024-09-24 19:56:47 -04:00
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
<Button onClick={handleFeedbackDialogClose} color="primary">
|
|
|
|
|
OK
|
|
|
|
|
</Button>
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</Dialog>
|
|
|
|
|
</div>
|
2024-03-29 20:08:34 -04:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TeacherModeQuiz;
|