mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
[BUG] Le progrès des étudiants n'est pas sauvegardé lorsqu'ils quittent et reviennent dans le quiz.
Fixes #296
This commit is contained in:
parent
112062c0b2
commit
182402e621
1 changed files with 48 additions and 2 deletions
|
|
@ -30,6 +30,7 @@ const ManageRoom: React.FC = () => {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [socket, setSocket] = useState<Socket | null>(null);
|
const [socket, setSocket] = useState<Socket | null>(null);
|
||||||
const [students, setStudents] = useState<StudentType[]>([]);
|
const [students, setStudents] = useState<StudentType[]>([]);
|
||||||
|
const [allStudents, setAllStudents] = useState<StudentType[]>([]);
|
||||||
const { quizId = '', roomName = '' } = useParams<{ quizId: string, roomName: string }>();
|
const { quizId = '', roomName = '' } = useParams<{ quizId: string, roomName: string }>();
|
||||||
const [quizQuestions, setQuizQuestions] = useState<QuestionType[] | undefined>();
|
const [quizQuestions, setQuizQuestions] = useState<QuestionType[] | undefined>();
|
||||||
const [quiz, setQuiz] = useState<QuizType | null>(null);
|
const [quiz, setQuiz] = useState<QuizType | null>(null);
|
||||||
|
|
@ -46,7 +47,8 @@ const ManageRoom: React.FC = () => {
|
||||||
if (newlyConnectedUser) {
|
if (newlyConnectedUser) {
|
||||||
console.log(`Handling newly connected user: ${newlyConnectedUser.name}`);
|
console.log(`Handling newly connected user: ${newlyConnectedUser.name}`);
|
||||||
setStudents((prevStudents) => [...prevStudents, newlyConnectedUser]);
|
setStudents((prevStudents) => [...prevStudents, newlyConnectedUser]);
|
||||||
|
setAllStudents((prevStudents) => [...prevStudents, newlyConnectedUser]);
|
||||||
|
|
||||||
// only send nextQuestion if the quiz has started
|
// only send nextQuestion if the quiz has started
|
||||||
if (!quizStarted) {
|
if (!quizStarted) {
|
||||||
console.log(`!quizStarted: returning.... `);
|
console.log(`!quizStarted: returning.... `);
|
||||||
|
|
@ -134,6 +136,8 @@ const ManageRoom: React.FC = () => {
|
||||||
setQuizQuestions(undefined);
|
setQuizQuestions(undefined);
|
||||||
setCurrentQuestion(undefined);
|
setCurrentQuestion(undefined);
|
||||||
setStudents(new Array<StudentType>());
|
setStudents(new Array<StudentType>());
|
||||||
|
setAllStudents(new Array<StudentType>());
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -245,6 +249,48 @@ const ManageRoom: React.FC = () => {
|
||||||
}
|
}
|
||||||
return updatedStudents;
|
return updatedStudents;
|
||||||
});
|
});
|
||||||
|
setAllStudents((prevStudents) => {
|
||||||
|
let foundStudent = false;
|
||||||
|
const updatedStudents = prevStudents.map((student) => {
|
||||||
|
console.log(`Comparing ${student.id} to ${idUser}`);
|
||||||
|
if (student.id === idUser) {
|
||||||
|
foundStudent = true;
|
||||||
|
const existingAnswer = student.answers.find(
|
||||||
|
(ans) => ans.idQuestion === idQuestion
|
||||||
|
);
|
||||||
|
let updatedAnswers: Answer[] = [];
|
||||||
|
if (existingAnswer) {
|
||||||
|
updatedAnswers = student.answers.map((ans) => {
|
||||||
|
console.log(`Comparing ${ans.idQuestion} to ${idQuestion}`);
|
||||||
|
return ans.idQuestion === idQuestion
|
||||||
|
? {
|
||||||
|
...ans,
|
||||||
|
answer,
|
||||||
|
isCorrect: checkIfIsCorrect(
|
||||||
|
answer,
|
||||||
|
idQuestion,
|
||||||
|
quizQuestions!
|
||||||
|
)
|
||||||
|
}
|
||||||
|
: ans;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const newAnswer = {
|
||||||
|
idQuestion,
|
||||||
|
answer,
|
||||||
|
isCorrect: checkIfIsCorrect(answer, idQuestion, quizQuestions!)
|
||||||
|
};
|
||||||
|
updatedAnswers = [...student.answers, newAnswer];
|
||||||
|
}
|
||||||
|
return { ...student, answers: updatedAnswers };
|
||||||
|
}
|
||||||
|
return student;
|
||||||
|
});
|
||||||
|
if (!foundStudent) {
|
||||||
|
console.log(`Student ${username} not found in the list.`);
|
||||||
|
}
|
||||||
|
return updatedStudents;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
setSocket(socket);
|
setSocket(socket);
|
||||||
}
|
}
|
||||||
|
|
@ -496,7 +542,7 @@ const ManageRoom: React.FC = () => {
|
||||||
socket={socket}
|
socket={socket}
|
||||||
questions={quizQuestions}
|
questions={quizQuestions}
|
||||||
showSelectedQuestion={showSelectedQuestion}
|
showSelectedQuestion={showSelectedQuestion}
|
||||||
students={students}
|
students={allStudents}
|
||||||
></LiveResultsComponent>
|
></LiveResultsComponent>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue