mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
parent
128ab6662e
commit
e61c855492
3 changed files with 9 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ import { Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/
|
|||
import { Question } from 'gift-pegjs';
|
||||
import { AnswerSubmissionToBackendType } from 'src/services/WebsocketService';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
import { useQuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
||||
// import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
interface TeacherModeQuizProps {
|
||||
|
|
@ -23,6 +24,8 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
|||
submitAnswer,
|
||||
disconnectWebSocket
|
||||
}) => {
|
||||
const { setShowAnswer } = useQuizContext(); // Access setShowAnswer from context
|
||||
|
||||
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
||||
const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false);
|
||||
const [answer, setAnswer] = useState<AnswerType>();
|
||||
|
|
@ -35,6 +38,7 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
|||
const oldAnswer = answers[Number(questionInfos.question.id) -1 ]?.answer;
|
||||
console.log(`TeacherModeQuiz: useEffect: oldAnswer: ${oldAnswer}`);
|
||||
setAnswer(oldAnswer);
|
||||
setShowAnswer(false);
|
||||
setIsFeedbackDialogOpen(false);
|
||||
}, [questionInfos.question, answers]);
|
||||
|
||||
|
|
@ -48,12 +52,13 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
|||
useEffect(() => {
|
||||
console.log(`TeacherModeQuiz: useEffect: isAnswerSubmitted: ${isAnswerSubmitted}`);
|
||||
setIsFeedbackDialogOpen(isAnswerSubmitted);
|
||||
setShowAnswer(isAnswerSubmitted);
|
||||
}, [isAnswerSubmitted]);
|
||||
|
||||
const handleOnSubmitAnswer = (answer: AnswerType) => {
|
||||
const idQuestion = Number(questionInfos.question.id) || -1;
|
||||
submitAnswer(answer, idQuestion);
|
||||
// setAnswer(answer);
|
||||
setAnswer(answer);
|
||||
setIsFeedbackDialogOpen(true);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -190,12 +190,14 @@ const JoinRoom: React.FC = () => {
|
|||
case 'teacher':
|
||||
return (
|
||||
question && (
|
||||
<QuizProvider>
|
||||
<TeacherModeQuiz
|
||||
questionInfos={question}
|
||||
answers={answers}
|
||||
submitAnswer={handleOnSubmitAnswer}
|
||||
disconnectWebSocket={disconnect}
|
||||
/>
|
||||
</QuizProvider>
|
||||
)
|
||||
);
|
||||
default:
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ export const QuizContext = React.createContext<{
|
|||
}>({
|
||||
showAnswer: false,
|
||||
setShowAnswer: () => {},
|
||||
|
||||
});
|
||||
|
||||
export const useQuizContext = () => {
|
||||
|
|
|
|||
Loading…
Reference in a new issue