2024-03-29 20:08:34 -04:00
|
|
|
// StudentModeQuiz.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';
|
2024-03-29 20:08:34 -04:00
|
|
|
import { Button } from '@mui/material';
|
2025-01-21 15:35:07 -05:00
|
|
|
//import QuestionNavigation from '../QuestionNavigation/QuestionNavigation';
|
|
|
|
|
//import { ChevronLeft, ChevronRight } from '@mui/icons-material';
|
2025-01-16 12:37:07 -05:00
|
|
|
import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
2025-01-25 02:02:18 -05:00
|
|
|
import { Question } from 'gift-pegjs';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
interface StudentModeQuizProps {
|
|
|
|
|
questions: 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 StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
|
|
|
|
questions,
|
|
|
|
|
submitAnswer,
|
|
|
|
|
disconnectWebSocket
|
|
|
|
|
}) => {
|
|
|
|
|
const [questionInfos, setQuestion] = useState<QuestionType>(questions[0]);
|
|
|
|
|
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
2024-09-15 00:34:41 -04:00
|
|
|
// const [imageUrl, setImageUrl] = useState('');
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-01-21 15:35:07 -05:00
|
|
|
// const previousQuestion = () => {
|
|
|
|
|
// setQuestion(questions[Number(questionInfos.question?.id) - 2]);
|
|
|
|
|
// setIsAnswerSubmitted(false);
|
|
|
|
|
// };
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2024-09-15 00:34:41 -04:00
|
|
|
useEffect(() => {}, [questionInfos]);
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
const nextQuestion = () => {
|
|
|
|
|
setQuestion(questions[Number(questionInfos.question?.id)]);
|
|
|
|
|
setIsAnswerSubmitted(false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
setIsAnswerSubmitted(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='room'>
|
|
|
|
|
<div className='roomHeader'>
|
|
|
|
|
|
|
|
|
|
<DisconnectButton
|
|
|
|
|
onReturn={disconnectWebSocket}
|
|
|
|
|
message={`Êtes-vous sûr de vouloir quitter?`} />
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
<div className="overflow-auto">
|
|
|
|
|
<div className="question-component-container">
|
|
|
|
|
<div className="mb-5">
|
2025-01-21 15:35:07 -05:00
|
|
|
{/* <QuestionNavigation
|
2024-03-29 20:08:34 -04:00
|
|
|
currentQuestionId={Number(questionInfos.question.id)}
|
|
|
|
|
questionsLength={questions.length}
|
|
|
|
|
previousQuestion={previousQuestion}
|
|
|
|
|
nextQuestion={nextQuestion}
|
2025-01-21 15:35:07 -05:00
|
|
|
/> */}
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
<QuestionComponent
|
|
|
|
|
handleOnSubmitAnswer={handleOnSubmitAnswer}
|
2025-01-25 02:02:18 -05:00
|
|
|
question={questionInfos.question as Question}
|
2024-03-29 20:08:34 -04:00
|
|
|
showAnswer={isAnswerSubmitted}
|
|
|
|
|
/>
|
|
|
|
|
<div className="center-h-align mt-1/2">
|
|
|
|
|
<div className="w-12">
|
2025-01-21 15:35:07 -05:00
|
|
|
{/* <Button
|
2024-03-29 20:08:34 -04:00
|
|
|
variant="outlined"
|
|
|
|
|
onClick={previousQuestion}
|
|
|
|
|
fullWidth
|
|
|
|
|
startIcon={<ChevronLeft />}
|
|
|
|
|
disabled={Number(questionInfos.question.id) <= 1}
|
|
|
|
|
>
|
|
|
|
|
Question précédente
|
2025-01-21 15:35:07 -05:00
|
|
|
</Button> */}
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
<div className="w-12">
|
2025-01-21 15:35:07 -05:00
|
|
|
<Button style={{ display: isAnswerSubmitted ? 'block' : 'none' }}
|
2024-03-29 20:08:34 -04:00
|
|
|
variant="outlined"
|
|
|
|
|
onClick={nextQuestion}
|
|
|
|
|
fullWidth
|
2025-01-21 15:35:07 -05:00
|
|
|
//endIcon={<ChevronRight />}
|
2024-03-29 20:08:34 -04:00
|
|
|
disabled={Number(questionInfos.question.id) >= questions.length}
|
|
|
|
|
>
|
|
|
|
|
Question suivante
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-01-21 15:35:07 -05:00
|
|
|
</div>
|
2024-03-29 20:08:34 -04:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default StudentModeQuiz;
|