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 { Question } from 'gift-pegjs';
|
||||||
import { AnswerSubmissionToBackendType } from 'src/services/WebsocketService';
|
import { AnswerSubmissionToBackendType } from 'src/services/WebsocketService';
|
||||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||||
|
import { useQuizContext } from 'src/pages/Student/JoinRoom/QuizContext';
|
||||||
// import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
// import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||||
|
|
||||||
interface TeacherModeQuizProps {
|
interface TeacherModeQuizProps {
|
||||||
|
|
@ -23,6 +24,8 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
submitAnswer,
|
submitAnswer,
|
||||||
disconnectWebSocket
|
disconnectWebSocket
|
||||||
}) => {
|
}) => {
|
||||||
|
const { setShowAnswer } = useQuizContext(); // Access setShowAnswer from context
|
||||||
|
|
||||||
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
||||||
const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false);
|
const [isFeedbackDialogOpen, setIsFeedbackDialogOpen] = useState(false);
|
||||||
const [answer, setAnswer] = useState<AnswerType>();
|
const [answer, setAnswer] = useState<AnswerType>();
|
||||||
|
|
@ -35,6 +38,7 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
const oldAnswer = answers[Number(questionInfos.question.id) -1 ]?.answer;
|
const oldAnswer = answers[Number(questionInfos.question.id) -1 ]?.answer;
|
||||||
console.log(`TeacherModeQuiz: useEffect: oldAnswer: ${oldAnswer}`);
|
console.log(`TeacherModeQuiz: useEffect: oldAnswer: ${oldAnswer}`);
|
||||||
setAnswer(oldAnswer);
|
setAnswer(oldAnswer);
|
||||||
|
setShowAnswer(false);
|
||||||
setIsFeedbackDialogOpen(false);
|
setIsFeedbackDialogOpen(false);
|
||||||
}, [questionInfos.question, answers]);
|
}, [questionInfos.question, answers]);
|
||||||
|
|
||||||
|
|
@ -48,12 +52,13 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log(`TeacherModeQuiz: useEffect: isAnswerSubmitted: ${isAnswerSubmitted}`);
|
console.log(`TeacherModeQuiz: useEffect: isAnswerSubmitted: ${isAnswerSubmitted}`);
|
||||||
setIsFeedbackDialogOpen(isAnswerSubmitted);
|
setIsFeedbackDialogOpen(isAnswerSubmitted);
|
||||||
|
setShowAnswer(isAnswerSubmitted);
|
||||||
}, [isAnswerSubmitted]);
|
}, [isAnswerSubmitted]);
|
||||||
|
|
||||||
const handleOnSubmitAnswer = (answer: AnswerType) => {
|
const handleOnSubmitAnswer = (answer: AnswerType) => {
|
||||||
const idQuestion = Number(questionInfos.question.id) || -1;
|
const idQuestion = Number(questionInfos.question.id) || -1;
|
||||||
submitAnswer(answer, idQuestion);
|
submitAnswer(answer, idQuestion);
|
||||||
// setAnswer(answer);
|
setAnswer(answer);
|
||||||
setIsFeedbackDialogOpen(true);
|
setIsFeedbackDialogOpen(true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -190,12 +190,14 @@ const JoinRoom: React.FC = () => {
|
||||||
case 'teacher':
|
case 'teacher':
|
||||||
return (
|
return (
|
||||||
question && (
|
question && (
|
||||||
|
<QuizProvider>
|
||||||
<TeacherModeQuiz
|
<TeacherModeQuiz
|
||||||
questionInfos={question}
|
questionInfos={question}
|
||||||
answers={answers}
|
answers={answers}
|
||||||
submitAnswer={handleOnSubmitAnswer}
|
submitAnswer={handleOnSubmitAnswer}
|
||||||
disconnectWebSocket={disconnect}
|
disconnectWebSocket={disconnect}
|
||||||
/>
|
/>
|
||||||
|
</QuizProvider>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ export const QuizContext = React.createContext<{
|
||||||
}>({
|
}>({
|
||||||
showAnswer: false,
|
showAnswer: false,
|
||||||
setShowAnswer: () => {},
|
setShowAnswer: () => {},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export const useQuizContext = () => {
|
export const useQuizContext = () => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue