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';
|
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);
|
2025-02-05 18:48:52 -05:00
|
|
|
const [feedbackMessage, setFeedbackMessage] = useState<React.ReactNode>('');
|
2025-03-03 17:00:42 -05:00
|
|
|
|
2025-02-05 18:48:52 -05:00
|
|
|
const renderFeedbackMessage = (answer: string) => {
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-02-05 18:48:52 -05:00
|
|
|
if(answer === 'true' || answer === 'false'){
|
|
|
|
|
return (<span>
|
|
|
|
|
<strong>Votre réponse est: </strong>{answer==="true" ? 'Vrai' : 'Faux'}
|
|
|
|
|
</span>)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return (
|
|
|
|
|
<span>
|
|
|
|
|
<strong>Votre réponse est: </strong>{answer.toString()}
|
|
|
|
|
</span>
|
|
|
|
|
);}
|
|
|
|
|
};
|
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-03-03 17:00:42 -05:00
|
|
|
const answer = localStorage.getItem(`Answer${questionInfos.question.id}`);
|
|
|
|
|
if (answer !== null) {
|
|
|
|
|
setIsAnswerSubmitted(true);
|
|
|
|
|
setIsFeedbackDialogOpen(true);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2025-03-03 17:00:42 -05:00
|
|
|
|
2025-02-05 18:48:52 -05:00
|
|
|
setFeedbackMessage(renderFeedbackMessage(answer.toString()));
|
2024-09-24 19:56:47 -04:00
|
|
|
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>
|
2025-02-05 18:48:52 -05:00
|
|
|
<div style={{
|
|
|
|
|
wordWrap: 'break-word',
|
|
|
|
|
whiteSpace: 'pre-wrap',
|
|
|
|
|
maxHeight: '400px',
|
|
|
|
|
overflowY: 'auto',
|
|
|
|
|
}}>
|
2024-09-24 19:56:47 -04:00
|
|
|
{feedbackMessage}
|
2025-02-05 18:48:52 -05:00
|
|
|
<div style={{ textAlign: 'left', fontWeight: 'bold', marginTop: '10px'}}
|
|
|
|
|
>Question : </div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2024-09-24 19:56:47 -04:00
|
|
|
<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;
|