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