2024-03-29 20:08:34 -04:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
|
import { useNavigate, useParams } from 'react-router-dom';
|
|
|
|
|
import { Socket } from 'socket.io-client';
|
2025-03-21 00:25:25 -04:00
|
|
|
import { BaseQuestion, parse, Question } from 'gift-pegjs';
|
2025-01-16 12:37:07 -05:00
|
|
|
import LiveResultsComponent from 'src/components/LiveResults/LiveResults';
|
2025-02-20 00:37:01 -05:00
|
|
|
import webSocketService, {
|
|
|
|
|
AnswerReceptionFromBackendType
|
|
|
|
|
} from '../../../services/WebsocketService';
|
2024-03-29 20:08:34 -04:00
|
|
|
import { QuizType } from '../../../Types/QuizType';
|
2025-01-23 20:12:47 -05:00
|
|
|
import GroupIcon from '@mui/icons-material/Group';
|
2024-03-29 20:08:34 -04:00
|
|
|
import './manageRoom.css';
|
2025-01-10 15:46:17 -05:00
|
|
|
import { ENV_VARIABLES } from 'src/constants';
|
2024-09-26 00:34:30 -04:00
|
|
|
import { StudentType, Answer } from '../../../Types/StudentType';
|
2025-01-16 12:37:07 -05:00
|
|
|
import LoadingCircle from 'src/components/LoadingCircle/LoadingCircle';
|
2024-03-29 20:08:34 -04:00
|
|
|
import { Refresh, Error } from '@mui/icons-material';
|
2025-01-16 12:37:07 -05:00
|
|
|
import StudentWaitPage from 'src/components/StudentWaitPage/StudentWaitPage';
|
|
|
|
|
import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
2025-01-25 02:02:18 -05:00
|
|
|
import QuestionDisplay from 'src/components/QuestionsDisplay/QuestionDisplay';
|
2024-03-29 20:08:34 -04:00
|
|
|
import ApiService from '../../../services/ApiService';
|
2025-01-25 02:02:18 -05:00
|
|
|
import { QuestionType } from 'src/Types/QuestionType';
|
2025-02-23 22:40:46 -05:00
|
|
|
import { Button } from '@mui/material';
|
2025-03-21 00:25:25 -04:00
|
|
|
import { checkIfIsCorrect } from './useRooms';
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
const ManageRoom: React.FC = () => {
|
|
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const [socket, setSocket] = useState<Socket | null>(null);
|
2024-09-25 13:05:36 -04:00
|
|
|
const [students, setStudents] = useState<StudentType[]>([]);
|
2025-03-24 02:52:41 -04:00
|
|
|
const { quizId = '', roomName = '' } = useParams<{ quizId: string; roomName: string }>();
|
2024-03-29 20:08:34 -04:00
|
|
|
const [quizQuestions, setQuizQuestions] = useState<QuestionType[] | undefined>();
|
|
|
|
|
const [quiz, setQuiz] = useState<QuizType | null>(null);
|
|
|
|
|
const [quizMode, setQuizMode] = useState<'teacher' | 'student'>('teacher');
|
|
|
|
|
const [connectingError, setConnectingError] = useState<string>('');
|
|
|
|
|
const [currentQuestion, setCurrentQuestion] = useState<QuestionType | undefined>(undefined);
|
2025-03-09 00:54:21 -05:00
|
|
|
const [quizStarted, setQuizStarted] = useState<boolean>(false);
|
2025-03-24 02:52:41 -04:00
|
|
|
const [formattedRoomName, setFormattedRoomName] = useState('');
|
2025-03-09 00:54:21 -05:00
|
|
|
const [newlyConnectedUser, setNewlyConnectedUser] = useState<StudentType | null>(null);
|
|
|
|
|
|
2025-03-24 02:52:41 -04:00
|
|
|
// Handle the newly connected user in useEffect, because it needs state info
|
2025-03-09 00:54:21 -05:00
|
|
|
// not available in the socket.on() callback
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (newlyConnectedUser) {
|
|
|
|
|
console.log(`Handling newly connected user: ${newlyConnectedUser.name}`);
|
|
|
|
|
setStudents((prevStudents) => [...prevStudents, newlyConnectedUser]);
|
2025-03-24 02:52:41 -04:00
|
|
|
|
2025-03-09 00:54:21 -05:00
|
|
|
// only send nextQuestion if the quiz has started
|
|
|
|
|
if (!quizStarted) {
|
|
|
|
|
console.log(`!quizStarted: returning.... `);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-03-24 02:52:41 -04:00
|
|
|
|
2025-03-09 00:54:21 -05:00
|
|
|
if (quizMode === 'teacher') {
|
|
|
|
|
webSocketService.nextQuestion({
|
|
|
|
|
roomName: formattedRoomName,
|
|
|
|
|
questions: quizQuestions,
|
|
|
|
|
questionIndex: Number(currentQuestion?.question.id) - 1,
|
|
|
|
|
isLaunch: true // started late
|
|
|
|
|
});
|
|
|
|
|
} else if (quizMode === 'student') {
|
|
|
|
|
webSocketService.launchStudentModeQuiz(formattedRoomName, quizQuestions);
|
|
|
|
|
} else {
|
|
|
|
|
console.error('Invalid quiz mode:', quizMode);
|
|
|
|
|
}
|
2025-03-24 02:52:41 -04:00
|
|
|
|
2025-03-09 00:54:21 -05:00
|
|
|
// Reset the newly connected user state
|
|
|
|
|
setNewlyConnectedUser(null);
|
|
|
|
|
}
|
2025-03-09 01:19:31 -05:00
|
|
|
}, [newlyConnectedUser]);
|
2025-02-27 15:49:09 -05:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const verifyLogin = async () => {
|
|
|
|
|
if (!ApiService.isLoggedIn()) {
|
|
|
|
|
navigate('/teacher/login');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
verifyLogin();
|
|
|
|
|
}, []);
|
2025-02-23 22:40:46 -05:00
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
useEffect(() => {
|
2025-02-26 14:38:36 -05:00
|
|
|
if (!roomName || !quizId) {
|
|
|
|
|
window.alert(
|
|
|
|
|
`Une erreur est survenue.\n La salle ou le quiz n'a pas été spécifié.\nVeuillez réessayer plus tard.`
|
|
|
|
|
);
|
2025-02-27 15:49:09 -05:00
|
|
|
console.error(`Room "${roomName}" or Quiz "${quizId}" not found.`);
|
2025-02-26 14:38:36 -05:00
|
|
|
navigate('/teacher/dashboard');
|
|
|
|
|
}
|
2025-02-27 15:49:09 -05:00
|
|
|
if (roomName && !socket) {
|
|
|
|
|
createWebSocketRoom();
|
2025-02-24 03:29:36 -05:00
|
|
|
}
|
2025-02-27 15:49:09 -05:00
|
|
|
return () => {
|
|
|
|
|
disconnectWebSocket();
|
2025-02-20 00:19:32 -05:00
|
|
|
};
|
2025-03-24 02:52:41 -04:00
|
|
|
}, [roomName, navigate]);
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2025-02-26 14:38:36 -05:00
|
|
|
if (quizId) {
|
2025-02-27 15:49:09 -05:00
|
|
|
const fetchQuiz = async () => {
|
2025-02-26 14:38:36 -05:00
|
|
|
const quiz = await ApiService.getQuiz(quizId);
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
if (!quiz) {
|
2025-02-20 00:37:01 -05:00
|
|
|
window.alert(
|
2025-02-26 14:38:36 -05:00
|
|
|
`Une erreur est survenue.\n Le quiz ${quizId} n'a pas été trouvé\nVeuillez réessayer plus tard`
|
2025-02-20 00:37:01 -05:00
|
|
|
);
|
2025-02-26 14:38:36 -05:00
|
|
|
console.error('Quiz not found for id:', quizId);
|
2024-03-29 20:08:34 -04:00
|
|
|
navigate('/teacher/dashboard');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setQuiz(quiz as QuizType);
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-27 15:49:09 -05:00
|
|
|
fetchQuiz();
|
2024-03-29 20:08:34 -04:00
|
|
|
} else {
|
2025-02-20 00:37:01 -05:00
|
|
|
window.alert(
|
2025-02-26 14:38:36 -05:00
|
|
|
`Une erreur est survenue.\n Le quiz ${quizId} n'a pas été trouvé\nVeuillez réessayer plus tard`
|
2025-02-20 00:37:01 -05:00
|
|
|
);
|
2025-02-26 14:38:36 -05:00
|
|
|
console.error('Quiz not found for id:', quizId);
|
2024-03-29 20:08:34 -04:00
|
|
|
navigate('/teacher/dashboard');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}, [quizId]);
|
|
|
|
|
|
|
|
|
|
const disconnectWebSocket = () => {
|
|
|
|
|
if (socket) {
|
2025-02-27 15:49:09 -05:00
|
|
|
webSocketService.endQuiz(formattedRoomName);
|
2024-03-29 20:08:34 -04:00
|
|
|
webSocketService.disconnect();
|
|
|
|
|
setSocket(null);
|
|
|
|
|
setQuizQuestions(undefined);
|
|
|
|
|
setCurrentQuestion(undefined);
|
2024-09-25 14:53:17 -04:00
|
|
|
setStudents(new Array<StudentType>());
|
2024-03-29 20:08:34 -04:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const createWebSocketRoom = () => {
|
2025-03-04 16:43:11 -05:00
|
|
|
const socket = webSocketService.connect(ENV_VARIABLES.VITE_BACKEND_URL);
|
2025-02-27 15:49:09 -05:00
|
|
|
const roomNameUpper = roomName.toUpperCase();
|
|
|
|
|
setFormattedRoomName(roomNameUpper);
|
|
|
|
|
console.log(`Creating WebSocket room named ${roomNameUpper}`);
|
2025-03-09 00:54:21 -05:00
|
|
|
|
2025-03-24 02:52:41 -04:00
|
|
|
/**
|
|
|
|
|
* ATTENTION: Lire les variables d'état dans
|
2025-03-09 00:54:21 -05:00
|
|
|
* les .on() n'est pas une bonne pratique.
|
|
|
|
|
* Les valeurs sont celles au moment de la création
|
|
|
|
|
* de la fonction et non au moment de l'exécution.
|
|
|
|
|
* Il faut utiliser des refs pour les valeurs qui
|
|
|
|
|
* changent fréquemment. Sinon, utiliser un trigger
|
|
|
|
|
* de useEffect pour mettre déclencher un traitement
|
|
|
|
|
* (voir user-joined plus bas).
|
|
|
|
|
*/
|
2024-03-29 20:08:34 -04:00
|
|
|
socket.on('connect', () => {
|
2025-02-27 15:49:09 -05:00
|
|
|
webSocketService.createRoom(roomNameUpper);
|
2024-03-29 20:08:34 -04:00
|
|
|
});
|
2025-02-24 03:29:36 -05:00
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
socket.on('connect_error', (error) => {
|
|
|
|
|
setConnectingError('Erreur lors de la connexion... Veuillez réessayer');
|
2024-10-30 17:19:11 -04:00
|
|
|
console.error('ManageRoom: WebSocket connection error:', error);
|
2024-03-29 20:08:34 -04:00
|
|
|
});
|
2025-02-24 03:29:36 -05:00
|
|
|
|
2025-02-27 15:49:09 -05:00
|
|
|
socket.on('create-success', (createdRoomName: string) => {
|
|
|
|
|
console.log(`Room created: ${createdRoomName}`);
|
2024-03-29 20:08:34 -04:00
|
|
|
});
|
2025-02-24 03:29:36 -05:00
|
|
|
|
2024-09-25 13:05:36 -04:00
|
|
|
socket.on('user-joined', (student: StudentType) => {
|
2025-03-09 00:54:21 -05:00
|
|
|
setNewlyConnectedUser(student);
|
2024-04-09 10:10:17 -04:00
|
|
|
});
|
2025-03-09 00:54:21 -05:00
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
socket.on('join-failure', (message) => {
|
|
|
|
|
setConnectingError(message);
|
|
|
|
|
setSocket(null);
|
|
|
|
|
});
|
2025-02-24 03:29:36 -05:00
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
socket.on('user-disconnected', (userId: string) => {
|
2024-09-25 16:31:38 -04:00
|
|
|
console.log(`Student left: id = ${userId}`);
|
2024-09-25 11:17:06 -04:00
|
|
|
setStudents((prevUsers) => prevUsers.filter((user) => user.id !== userId));
|
2024-03-29 20:08:34 -04:00
|
|
|
});
|
2025-01-23 20:12:47 -05:00
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
setSocket(socket);
|
|
|
|
|
};
|
|
|
|
|
|
2024-04-06 19:25:30 -04:00
|
|
|
useEffect(() => {
|
2024-09-26 00:34:30 -04:00
|
|
|
if (socket) {
|
2025-02-27 15:49:09 -05:00
|
|
|
console.log(`Listening for submit-answer-room in room ${formattedRoomName}`);
|
2024-09-26 00:34:30 -04:00
|
|
|
socket.on('submit-answer-room', (answerData: AnswerReceptionFromBackendType) => {
|
|
|
|
|
const { answer, idQuestion, idUser, username } = answerData;
|
2025-02-24 03:29:36 -05:00
|
|
|
console.log(
|
|
|
|
|
`Received answer from ${username} for question ${idQuestion}: ${answer}`
|
|
|
|
|
);
|
2024-09-26 00:34:30 -04:00
|
|
|
if (!quizQuestions) {
|
|
|
|
|
console.log('Quiz questions not found (cannot update answers without them).');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-01-23 20:12:47 -05:00
|
|
|
|
2024-09-26 00:34:30 -04:00
|
|
|
// Update the students state using the functional form of setStudents
|
|
|
|
|
setStudents((prevStudents) => {
|
|
|
|
|
console.log('Current students:');
|
|
|
|
|
prevStudents.forEach((student) => {
|
|
|
|
|
console.log(student.name);
|
|
|
|
|
});
|
2025-01-23 20:12:47 -05:00
|
|
|
|
2024-09-26 00:34:30 -04:00
|
|
|
let foundStudent = false;
|
|
|
|
|
const updatedStudents = prevStudents.map((student) => {
|
|
|
|
|
console.log(`Comparing ${student.id} to ${idUser}`);
|
|
|
|
|
if (student.id === idUser) {
|
|
|
|
|
foundStudent = true;
|
2025-02-24 03:29:36 -05:00
|
|
|
const existingAnswer = student.answers.find(
|
|
|
|
|
(ans) => ans.idQuestion === idQuestion
|
|
|
|
|
);
|
2024-09-26 00:34:30 -04:00
|
|
|
let updatedAnswers: Answer[] = [];
|
|
|
|
|
if (existingAnswer) {
|
|
|
|
|
updatedAnswers = student.answers.map((ans) => {
|
|
|
|
|
console.log(`Comparing ${ans.idQuestion} to ${idQuestion}`);
|
2025-02-24 03:29:36 -05:00
|
|
|
return ans.idQuestion === idQuestion
|
|
|
|
|
? {
|
|
|
|
|
...ans,
|
|
|
|
|
answer,
|
|
|
|
|
isCorrect: checkIfIsCorrect(
|
|
|
|
|
answer,
|
|
|
|
|
idQuestion,
|
|
|
|
|
quizQuestions!
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
: ans;
|
2024-09-26 00:34:30 -04:00
|
|
|
});
|
|
|
|
|
} else {
|
2025-02-24 03:29:36 -05:00
|
|
|
const newAnswer = {
|
|
|
|
|
idQuestion,
|
|
|
|
|
answer,
|
|
|
|
|
isCorrect: checkIfIsCorrect(answer, idQuestion, quizQuestions!)
|
|
|
|
|
};
|
2024-09-26 00:34:30 -04:00
|
|
|
updatedAnswers = [...student.answers, newAnswer];
|
|
|
|
|
}
|
|
|
|
|
return { ...student, answers: updatedAnswers };
|
2025-01-23 20:12:47 -05:00
|
|
|
}
|
2024-09-26 00:34:30 -04:00
|
|
|
return student;
|
|
|
|
|
});
|
|
|
|
|
if (!foundStudent) {
|
|
|
|
|
console.log(`Student ${username} not found in the list.`);
|
|
|
|
|
}
|
|
|
|
|
return updatedStudents;
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
setSocket(socket);
|
|
|
|
|
}
|
|
|
|
|
}, [socket, currentQuestion, quizQuestions]);
|
|
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
const nextQuestion = () => {
|
|
|
|
|
if (!quizQuestions || !currentQuestion || !quiz?.content) return;
|
|
|
|
|
|
|
|
|
|
const nextQuestionIndex = Number(currentQuestion?.question.id);
|
|
|
|
|
|
|
|
|
|
if (nextQuestionIndex === undefined || nextQuestionIndex > quizQuestions.length - 1) return;
|
|
|
|
|
|
|
|
|
|
setCurrentQuestion(quizQuestions[nextQuestionIndex]);
|
2025-03-24 02:52:41 -04:00
|
|
|
webSocketService.nextQuestion({
|
|
|
|
|
roomName: formattedRoomName,
|
|
|
|
|
questions: quizQuestions,
|
|
|
|
|
questionIndex: nextQuestionIndex,
|
|
|
|
|
isLaunch: false
|
|
|
|
|
});
|
2024-03-29 20:08:34 -04:00
|
|
|
};
|
|
|
|
|
|
2025-01-22 15:28:45 -05:00
|
|
|
const previousQuestion = () => {
|
|
|
|
|
if (!quizQuestions || !currentQuestion || !quiz?.content) return;
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-01-22 15:28:45 -05:00
|
|
|
const prevQuestionIndex = Number(currentQuestion?.question.id) - 2; // -2 because question.id starts at index 1
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2025-01-22 15:28:45 -05:00
|
|
|
if (prevQuestionIndex === undefined || prevQuestionIndex < 0) return;
|
|
|
|
|
setCurrentQuestion(quizQuestions[prevQuestionIndex]);
|
2025-03-24 02:52:41 -04:00
|
|
|
webSocketService.nextQuestion({
|
|
|
|
|
roomName: formattedRoomName,
|
|
|
|
|
questions: quizQuestions,
|
|
|
|
|
questionIndex: prevQuestionIndex,
|
|
|
|
|
isLaunch: false
|
|
|
|
|
});
|
2025-01-22 15:28:45 -05:00
|
|
|
};
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
const initializeQuizQuestion = () => {
|
|
|
|
|
const quizQuestionArray = quiz?.content;
|
|
|
|
|
if (!quizQuestionArray) return null;
|
|
|
|
|
const parsedQuestions = [] as QuestionType[];
|
|
|
|
|
|
|
|
|
|
quizQuestionArray.forEach((question, index) => {
|
2025-01-25 02:02:18 -05:00
|
|
|
parsedQuestions.push({ question: parse(question)[0] as BaseQuestion });
|
2024-03-29 20:08:34 -04:00
|
|
|
parsedQuestions[index].question.id = (index + 1).toString();
|
|
|
|
|
});
|
|
|
|
|
if (parsedQuestions.length === 0) return null;
|
|
|
|
|
|
|
|
|
|
setQuizQuestions(parsedQuestions);
|
|
|
|
|
return parsedQuestions;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const launchTeacherMode = () => {
|
|
|
|
|
const quizQuestions = initializeQuizQuestion();
|
2024-09-26 00:34:30 -04:00
|
|
|
console.log('launchTeacherMode - quizQuestions:', quizQuestions);
|
2024-03-29 20:08:34 -04:00
|
|
|
|
2024-09-26 00:34:30 -04:00
|
|
|
if (!quizQuestions) {
|
|
|
|
|
console.log('Error launching quiz (launchTeacherMode). No questions found.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
setCurrentQuestion(quizQuestions[0]);
|
2025-03-24 02:52:41 -04:00
|
|
|
webSocketService.nextQuestion({
|
|
|
|
|
roomName: formattedRoomName,
|
|
|
|
|
questions: quizQuestions,
|
|
|
|
|
questionIndex: 0,
|
|
|
|
|
isLaunch: true
|
|
|
|
|
});
|
2024-03-29 20:08:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const launchStudentMode = () => {
|
|
|
|
|
const quizQuestions = initializeQuizQuestion();
|
2024-09-26 00:34:30 -04:00
|
|
|
console.log('launchStudentMode - quizQuestions:', quizQuestions);
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
if (!quizQuestions) {
|
2024-09-26 00:34:30 -04:00
|
|
|
console.log('Error launching quiz (launchStudentMode). No questions found.');
|
2024-03-29 20:08:34 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2024-09-26 00:34:30 -04:00
|
|
|
setQuizQuestions(quizQuestions);
|
2025-02-27 15:49:09 -05:00
|
|
|
webSocketService.launchStudentModeQuiz(formattedRoomName, quizQuestions);
|
2024-03-29 20:08:34 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const launchQuiz = () => {
|
2025-03-09 00:54:21 -05:00
|
|
|
setQuizStarted(true);
|
2025-02-27 15:49:09 -05:00
|
|
|
if (!socket || !formattedRoomName || !quiz?.content || quiz?.content.length === 0) {
|
2024-09-24 19:56:47 -04:00
|
|
|
// TODO: This error happens when token expires! Need to handle it properly
|
2025-02-20 00:37:01 -05:00
|
|
|
console.log(
|
2025-02-27 15:49:09 -05:00
|
|
|
`Error launching quiz. socket: ${socket}, roomName: ${formattedRoomName}, quiz: ${quiz}`
|
2025-02-20 00:37:01 -05:00
|
|
|
);
|
2024-03-29 20:08:34 -04:00
|
|
|
return;
|
|
|
|
|
}
|
2025-03-09 00:54:21 -05:00
|
|
|
console.log(`Launching quiz in ${quizMode} mode...`);
|
2024-03-29 20:08:34 -04:00
|
|
|
switch (quizMode) {
|
|
|
|
|
case 'student':
|
|
|
|
|
return launchStudentMode();
|
|
|
|
|
case 'teacher':
|
|
|
|
|
return launchTeacherMode();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const showSelectedQuestion = (questionIndex: number) => {
|
|
|
|
|
if (quiz?.content && quizQuestions) {
|
|
|
|
|
setCurrentQuestion(quizQuestions[questionIndex]);
|
|
|
|
|
if (quizMode === 'teacher') {
|
2025-03-24 02:52:41 -04:00
|
|
|
webSocketService.nextQuestion({
|
|
|
|
|
roomName: formattedRoomName,
|
|
|
|
|
questions: quizQuestions,
|
|
|
|
|
questionIndex,
|
|
|
|
|
isLaunch: false
|
|
|
|
|
});
|
2024-03-29 20:08:34 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-24 02:52:41 -04:00
|
|
|
const finishQuiz = () => {
|
|
|
|
|
disconnectWebSocket();
|
|
|
|
|
navigate('/teacher/dashboard');
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-29 20:08:34 -04:00
|
|
|
const handleReturn = () => {
|
|
|
|
|
disconnectWebSocket();
|
|
|
|
|
navigate('/teacher/dashboard');
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-27 15:49:09 -05:00
|
|
|
if (!formattedRoomName) {
|
2024-03-29 20:08:34 -04:00
|
|
|
return (
|
|
|
|
|
<div className="center">
|
|
|
|
|
{!connectingError ? (
|
|
|
|
|
<LoadingCircle text="Veuillez attendre la connexion au serveur..." />
|
|
|
|
|
) : (
|
|
|
|
|
<div className="center-v-align">
|
|
|
|
|
<Error sx={{ padding: 0 }} />
|
|
|
|
|
<div className="text-base">{connectingError}</div>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
startIcon={<Refresh />}
|
|
|
|
|
onClick={createWebSocketRoom}
|
|
|
|
|
>
|
|
|
|
|
Reconnecter
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2025-02-20 00:37:01 -05:00
|
|
|
<div className="room">
|
2025-02-27 15:49:09 -05:00
|
|
|
<h1>Salle : {formattedRoomName}</h1>
|
2025-02-20 00:37:01 -05:00
|
|
|
<div className="roomHeader">
|
2024-03-29 20:08:34 -04:00
|
|
|
<DisconnectButton
|
|
|
|
|
onReturn={handleReturn}
|
|
|
|
|
askConfirm
|
2025-02-20 00:37:01 -05:00
|
|
|
message={`Êtes-vous sûr de vouloir quitter?`}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
className="headerContent"
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
justifyContent: 'space-between',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
width: '100%'
|
|
|
|
|
}}
|
|
|
|
|
>
|
2025-03-24 02:52:41 -04:00
|
|
|
{
|
2025-02-20 00:37:01 -05:00
|
|
|
<div
|
|
|
|
|
className="userCount subtitle smallText"
|
2025-03-24 02:52:41 -04:00
|
|
|
style={{ display: 'flex', justifyContent: 'flex-end' }}
|
2025-02-20 00:37:01 -05:00
|
|
|
>
|
2025-01-23 20:12:47 -05:00
|
|
|
<GroupIcon style={{ marginRight: '5px' }} />
|
|
|
|
|
{students.length}/60
|
|
|
|
|
</div>
|
2025-03-24 02:52:41 -04:00
|
|
|
}
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
|
2025-02-20 00:37:01 -05:00
|
|
|
<div className="dumb"></div>
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
|
2025-02-20 00:37:01 -05:00
|
|
|
{/* the following breaks the css (if 'room' classes are nested) */}
|
|
|
|
|
<div className="">
|
2024-03-29 20:08:34 -04:00
|
|
|
{quizQuestions ? (
|
|
|
|
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
|
|
|
|
<div className="title center-h-align mb-2">{quiz?.title}</div>
|
2025-01-23 20:23:15 -05:00
|
|
|
{!isNaN(Number(currentQuestion?.question.id)) && (
|
2025-02-20 00:37:01 -05:00
|
|
|
<strong className="number of questions">
|
|
|
|
|
Question {Number(currentQuestion?.question.id)}/
|
|
|
|
|
{quizQuestions?.length}
|
2025-01-23 20:23:15 -05:00
|
|
|
</strong>
|
|
|
|
|
)}
|
2024-03-29 20:08:34 -04:00
|
|
|
|
|
|
|
|
{quizMode === 'teacher' && (
|
|
|
|
|
<div className="mb-1">
|
2025-01-21 15:35:07 -05:00
|
|
|
{/* <QuestionNavigation
|
2024-03-29 20:08:34 -04:00
|
|
|
currentQuestionId={Number(currentQuestion?.question.id)}
|
|
|
|
|
questionsLength={quizQuestions?.length}
|
|
|
|
|
previousQuestion={previousQuestion}
|
|
|
|
|
nextQuestion={nextQuestion}
|
2025-01-21 15:35:07 -05:00
|
|
|
/> */}
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="mb-2 flex-column-wrapper">
|
|
|
|
|
<div className="preview-and-result-container">
|
|
|
|
|
{currentQuestion && (
|
2025-01-23 22:38:22 -05:00
|
|
|
<QuestionDisplay
|
2024-03-29 20:08:34 -04:00
|
|
|
showAnswer={false}
|
2025-01-25 02:02:18 -05:00
|
|
|
question={currentQuestion?.question as Question}
|
2024-03-29 20:08:34 -04:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<LiveResultsComponent
|
|
|
|
|
quizMode={quizMode}
|
|
|
|
|
socket={socket}
|
|
|
|
|
questions={quizQuestions}
|
|
|
|
|
showSelectedQuestion={showSelectedQuestion}
|
2024-09-26 00:34:30 -04:00
|
|
|
students={students}
|
2024-03-29 20:08:34 -04:00
|
|
|
></LiveResultsComponent>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{quizMode === 'teacher' && (
|
2025-02-20 00:37:01 -05:00
|
|
|
<div
|
|
|
|
|
className="questionNavigationButtons"
|
|
|
|
|
style={{ display: 'flex', justifyContent: 'center' }}
|
|
|
|
|
>
|
2025-01-23 20:12:47 -05:00
|
|
|
<div className="previousQuestionButton">
|
2025-02-20 00:37:01 -05:00
|
|
|
<Button
|
|
|
|
|
onClick={previousQuestion}
|
2025-01-23 20:12:47 -05:00
|
|
|
variant="contained"
|
2025-02-20 00:37:01 -05:00
|
|
|
disabled={Number(currentQuestion?.question.id) <= 1}
|
|
|
|
|
>
|
2025-01-23 20:12:47 -05:00
|
|
|
Question précédente
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="nextQuestionButton">
|
2025-02-20 00:37:01 -05:00
|
|
|
<Button
|
|
|
|
|
onClick={nextQuestion}
|
2025-01-23 20:12:47 -05:00
|
|
|
variant="contained"
|
2025-02-20 00:37:01 -05:00
|
|
|
disabled={
|
|
|
|
|
Number(currentQuestion?.question.id) >=
|
|
|
|
|
quizQuestions.length
|
|
|
|
|
}
|
2025-01-23 20:12:47 -05:00
|
|
|
>
|
|
|
|
|
Prochaine question
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2025-02-20 00:37:01 -05:00
|
|
|
</div>
|
|
|
|
|
)}
|
2025-03-24 02:52:41 -04:00
|
|
|
<div className="finishQuizButton">
|
|
|
|
|
<Button onClick={finishQuiz} variant="contained">
|
|
|
|
|
Terminer le quiz
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
2024-03-29 20:08:34 -04:00
|
|
|
</div>
|
|
|
|
|
) : (
|
2024-09-25 13:20:09 -04:00
|
|
|
<StudentWaitPage
|
2024-09-25 14:53:17 -04:00
|
|
|
students={students}
|
2024-03-29 20:08:34 -04:00
|
|
|
launchQuiz={launchQuiz}
|
|
|
|
|
setQuizMode={setQuizMode}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default ManageRoom;
|