mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
fix bug for user join
This commit is contained in:
parent
e32dff3461
commit
d995b259e3
1 changed files with 17 additions and 19 deletions
|
|
@ -98,25 +98,7 @@ const ManageRoom: React.FC = () => {
|
|||
console.log('Error creating room.');
|
||||
});
|
||||
|
||||
socket.on('user-joined', (user: UserType) => {
|
||||
console.log("USER JOINED ! ")
|
||||
console.log("quizMode: ", quizMode)
|
||||
|
||||
setUsers((prevUsers) => [...prevUsers, user]);
|
||||
|
||||
// This doesn't relaunch the quiz for users that connected late
|
||||
if (quizMode === 'teacher') {
|
||||
console.log("TEACHER")
|
||||
|
||||
webSocketService.nextQuestion(roomName, currentQuestion);
|
||||
|
||||
} else if (quizMode === 'student') {
|
||||
|
||||
console.log(quizQuestions);
|
||||
webSocketService.launchStudentModeQuiz(roomName, quizQuestions);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
socket.on('join-failure', (message) => {
|
||||
setConnectingError(message);
|
||||
setSocket(null);
|
||||
|
|
@ -128,6 +110,22 @@ const ManageRoom: React.FC = () => {
|
|||
setSocket(socket);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// This is here to make sure the correct value is sent when user join
|
||||
if (socket) {
|
||||
socket.on('user-joined', (user: UserType) => {
|
||||
|
||||
setUsers((prevUsers) => [...prevUsers, user]);
|
||||
|
||||
if (quizMode === 'teacher') {
|
||||
webSocketService.nextQuestion(roomName, currentQuestion);
|
||||
} else if (quizMode === 'student') {
|
||||
webSocketService.launchStudentModeQuiz(roomName, quizQuestions);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, [currentQuestion, quizQuestions]);
|
||||
|
||||
const nextQuestion = () => {
|
||||
if (!quizQuestions || !currentQuestion || !quiz?.content) return;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue