diff --git a/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx index fcbbe51..5c947b5 100644 --- a/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay.tsx @@ -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(() => { - 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 = () => { diff --git a/client/src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx index d46981d..fa9ea3c 100644 --- a/client/src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/NumericalQuestionDisplay/NumericalQuestionDisplay.tsx @@ -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(answer || []); const correctAnswers = question.choices; diff --git a/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx index d3e0fbc..6d3bbf0 100644 --- a/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay.tsx @@ -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(answer || []); const question = questions[Number(index)].question as ShortAnswerQuestion; diff --git a/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx b/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx index 343f5f9..701b44d 100644 --- a/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx +++ b/client/src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay.tsx @@ -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(() => { + if (answer && (answer[0] === true || answer[0] === false)) { return answer[0]; } diff --git a/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx b/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx index 1008cce..036fd98 100644 --- a/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx +++ b/client/src/components/StudentModeQuiz/StudentModeQuiz.tsx @@ -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]); diff --git a/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx b/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx index 5852da6..a026c53 100644 --- a/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx +++ b/client/src/components/TeacherModeQuiz/TeacherModeQuiz.tsx @@ -93,9 +93,7 @@ const TeacherModeQuiz: React.FC = () => { >Question : - +