mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
studentMode working
This commit is contained in:
parent
7dcbe55776
commit
de50b6c4f0
9 changed files with 31 additions and 32 deletions
|
|
@ -9,14 +9,16 @@ import { useQuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
|||
import { QuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
||||
|
||||
const MultipleChoiceQuestionDisplay: React.FC = () => {
|
||||
const { questions, index, answer, submitAnswer } = useQuizContext();
|
||||
console.log('MultipleChoiceQuestionDisplay: passedAnswer', JSON.stringify(answer));
|
||||
const { questions, index, submitAnswer,answers } = useQuizContext();
|
||||
console.log("questions", index);
|
||||
|
||||
const answer = answers[Number(index)]?.answer;
|
||||
|
||||
const question = questions[Number(index)].question as MultipleChoiceQuestion;
|
||||
|
||||
const [actualAnswer, setActualAnswer] = useState<AnswerType>(() => {
|
||||
if (answer && answer === undefined) {
|
||||
return answer;
|
||||
if (answer !== undefined) {
|
||||
return answers[Number(index)].answer;
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
|
@ -27,13 +29,12 @@ const MultipleChoiceQuestionDisplay: React.FC = () => {
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
console.log('MultipleChoiceQuestionDisplay: passedAnswer', JSON.stringify(answer));
|
||||
if (answer.length !== undefined) {
|
||||
if (answer !== undefined) {
|
||||
setActualAnswer(answer);
|
||||
} else {
|
||||
setActualAnswer([]);
|
||||
}
|
||||
}, [answer, index]);
|
||||
}, [index]);
|
||||
|
||||
const handleOnClickAnswer = (choice: string) => {
|
||||
setActualAnswer((answer) => {
|
||||
|
|
@ -118,9 +119,9 @@ const MultipleChoiceQuestionDisplay: React.FC = () => {
|
|||
<Button
|
||||
variant="contained"
|
||||
onClick={() =>
|
||||
actualAnswer.length > 0 && submitAnswer && submitAnswer(actualAnswer)
|
||||
actualAnswer !== undefined && submitAnswer && submitAnswer(actualAnswer)
|
||||
}
|
||||
disabled={actualAnswer.length === 0}
|
||||
disabled={actualAnswer === undefined}
|
||||
>
|
||||
Répondre
|
||||
</Button>
|
||||
|
|
|
|||
|
|
@ -10,9 +10,10 @@ import { useQuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
|||
import { QuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
||||
|
||||
const NumericalQuestionDisplay: React.FC = () => {
|
||||
const { questions, index, answer, submitAnswer } = useQuizContext();
|
||||
const { questions, index, answers , submitAnswer } = useQuizContext();
|
||||
|
||||
const question = questions[Number(index)].question as NumericalQuestion;
|
||||
const answer = answers[Number(index)]?.answer;
|
||||
|
||||
const [actualAnswer, setActualAnswer] = useState<AnswerType>(answer || []);
|
||||
const correctAnswers = question.choices;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ import { QuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
|||
|
||||
const ShortAnswerQuestionDisplay: React.FC = () => {
|
||||
|
||||
const { questions, index, answer, submitAnswer } = useQuizContext();
|
||||
const { questions, index, submitAnswer, answers } = useQuizContext();
|
||||
|
||||
const answer = answers[Number(index)]?.answer;
|
||||
const [actualAnswer, setActualAnswer] = useState<AnswerType>(answer || []);
|
||||
const question = questions[Number(index)].question as ShortAnswerQuestion;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,13 @@ import { useQuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
|||
|
||||
const TrueFalseQuestionDisplay: React.FC = () => {
|
||||
|
||||
const { questions, index, answer, submitAnswer } = useQuizContext();
|
||||
const { questions, index, submitAnswer, answers } = useQuizContext();
|
||||
|
||||
const question = questions[Number(index)].question as TrueFalseQuestion;
|
||||
const answer = answers[Number(index)]?.answer;
|
||||
|
||||
const [actualAnswer, setActualAnswer] = useState<boolean | undefined>(() => {
|
||||
|
||||
if (answer && (answer[0] === true || answer[0] === false)) {
|
||||
return answer[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,11 +15,9 @@ const StudentModeQuiz: React.FC = () => {
|
|||
|
||||
useEffect(() => {
|
||||
let savedAnswer = undefined;
|
||||
console.log(`StudentModeQuiz: useEffect: index: ${index}`);
|
||||
if (answers.length === 0) {
|
||||
savedAnswer = answers[Number(index) - 1]?.answer;}
|
||||
if (answers.length !== 0) {
|
||||
savedAnswer = answers[Number(index)]?.answer;}
|
||||
|
||||
console.log(`StudentModeQuiz: useEffect: savedAnswer: ${savedAnswer}`);
|
||||
setIsQuestionSent(savedAnswer !== undefined);
|
||||
setShowAnswer(savedAnswer !== undefined); // Update showAnswer in context
|
||||
}, [index, answers, setShowAnswer]);
|
||||
|
|
|
|||
|
|
@ -93,9 +93,7 @@ const TeacherModeQuiz: React.FC = () => {
|
|||
>Question : </div>
|
||||
</div>
|
||||
|
||||
<QuestionDisplay
|
||||
//showAnswer={true}
|
||||
/>
|
||||
<QuestionDisplay/>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={handleFeedbackDialogClose} color="primary">
|
||||
|
|
|
|||
|
|
@ -55,9 +55,7 @@ const JoinRoom: React.FC = () => {
|
|||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
console.log(`JoinRoom: useEffect: questions: ${JSON.stringify(questions)}`);
|
||||
setAnswers(questions ? Array(questions.length).fill({} as AnswerSubmissionToBackendType) : []);
|
||||
console.log(`JoinRoom: useEffect: answers: ${JSON.stringify(questions)}`);
|
||||
}, [questions]);
|
||||
|
||||
|
||||
|
|
@ -128,6 +126,7 @@ const JoinRoom: React.FC = () => {
|
|||
setRoomName('');
|
||||
setUsername('');
|
||||
setIsConnecting(false);
|
||||
setAnswers([]);
|
||||
};
|
||||
|
||||
const handleSocket = () => {
|
||||
|
|
|
|||
|
|
@ -39,29 +39,27 @@ export const QuizProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
|||
};
|
||||
|
||||
// Function to handle answer submission
|
||||
const submitAnswer = (answer: AnswerType, idQuestion?: number) => {
|
||||
if (!idQuestion) {
|
||||
setAnswer(answer);
|
||||
setIsQuestionSent(true);
|
||||
} else {
|
||||
const submitAnswer = (answer: AnswerType) => {
|
||||
|
||||
const answerData: AnswerSubmissionToBackendType = {
|
||||
roomName: roomName,
|
||||
answer: answer,
|
||||
username: username,
|
||||
idQuestion: idQuestion,
|
||||
idQuestion: Number(index),
|
||||
};
|
||||
|
||||
setAnswer(answer);
|
||||
setIsQuestionSent(true);
|
||||
// Update the answers state
|
||||
setAnswers((prevAnswers) => {
|
||||
const newAnswers = [...prevAnswers]; // Create a copy of the previous answers array
|
||||
newAnswers[idQuestion - 1] = answerData; // Update the specific answer
|
||||
newAnswers[Number(index)] = answerData; // Update the specific answer
|
||||
return newAnswers; // Return the new array
|
||||
});
|
||||
|
||||
console.log(`submitAnswer: answerData: ${JSON.stringify(answers)}`);
|
||||
|
||||
// Submit the answer to the WebSocket service
|
||||
webSocketService.submitAnswer(answerData);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -299,7 +299,7 @@ const ManageRoom: React.FC = () => {
|
|||
console.log('Error launching quiz (launchTeacherMode). No questions found.');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
updateIndex(0);
|
||||
webSocketService.nextQuestion({roomName: formattedRoomName, questions: questions, questionIndex: 0, isLaunch: true});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue