mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Compare commits
2 commits
de50b6c4f0
...
241d0d1cf7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
241d0d1cf7 | ||
|
|
5a710fff11 |
7 changed files with 29 additions and 18 deletions
|
|
@ -13,7 +13,6 @@ const MultipleChoiceQuestionDisplay: React.FC = () => {
|
||||||
console.log("questions", index);
|
console.log("questions", index);
|
||||||
|
|
||||||
const answer = answers[Number(index)]?.answer;
|
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>(() => {
|
||||||
|
|
@ -62,7 +61,7 @@ const MultipleChoiceQuestionDisplay: React.FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QuizContext.Consumer>
|
<QuizContext.Consumer>
|
||||||
{({ showAnswer }) => (
|
{({ showAnswer, isTeacherMode }) => (
|
||||||
<div className="question-container">
|
<div className="question-container">
|
||||||
<div className="question content">
|
<div className="question content">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
||||||
|
|
@ -76,7 +75,7 @@ const MultipleChoiceQuestionDisplay: React.FC = () => {
|
||||||
<Button
|
<Button
|
||||||
variant="text"
|
variant="text"
|
||||||
className="button-wrapper"
|
className="button-wrapper"
|
||||||
disabled={disableButton}
|
disabled={disableButton || isTeacherMode}
|
||||||
onClick={() => !showAnswer && handleOnClickAnswer(choice.formattedText.text)}
|
onClick={() => !showAnswer && handleOnClickAnswer(choice.formattedText.text)}
|
||||||
>
|
>
|
||||||
{showAnswer ? (
|
{showAnswer ? (
|
||||||
|
|
@ -115,7 +114,7 @@ const MultipleChoiceQuestionDisplay: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!showAnswer && submitAnswer && (
|
{!showAnswer && submitAnswer && !isTeacherMode &&(
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ const NumericalQuestionDisplay: React.FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QuizContext.Consumer>
|
<QuizContext.Consumer>
|
||||||
{({ showAnswer }) => (
|
{({ showAnswer, isTeacherMode }) => (
|
||||||
<div className="question-wrapper">
|
<div className="question-wrapper">
|
||||||
<div>
|
<div>
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
||||||
|
|
@ -71,6 +71,7 @@ const NumericalQuestionDisplay: React.FC = () => {
|
||||||
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setActualAnswer([e.target.valueAsNumber]);
|
setActualAnswer([e.target.valueAsNumber]);
|
||||||
}}
|
}}
|
||||||
|
disabled={showAnswer || isTeacherMode}
|
||||||
inputProps={{ 'data-testid': 'number-input' }}
|
inputProps={{ 'data-testid': 'number-input' }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -79,7 +80,7 @@ const NumericalQuestionDisplay: React.FC = () => {
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedGlobalFeedback) }} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{submitAnswer && (
|
{submitAnswer && !isTeacherMode &&(
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const ShortAnswerQuestionDisplay: React.FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QuizContext.Consumer>
|
<QuizContext.Consumer>
|
||||||
{({ showAnswer }) => (
|
{({ showAnswer, isTeacherMode }) => (
|
||||||
<div className="question-wrapper">
|
<div className="question-wrapper">
|
||||||
<div className="question content">
|
<div className="question content">
|
||||||
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
<div dangerouslySetInnerHTML={{ __html: FormattedTextTemplate(question.formattedStem) }} />
|
||||||
|
|
@ -60,11 +60,11 @@ const ShortAnswerQuestionDisplay: React.FC = () => {
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setActualAnswer([e.target.value]);
|
setActualAnswer([e.target.value]);
|
||||||
}}
|
}}
|
||||||
disabled={showAnswer}
|
disabled={showAnswer || isTeacherMode}
|
||||||
aria-label="short-answer-input"
|
aria-label="short-answer-input"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{submitAnswer && (
|
{submitAnswer && !isTeacherMode && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ const TrueFalseQuestionDisplay: React.FC = () => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<QuizContext.Consumer>
|
<QuizContext.Consumer>
|
||||||
{({ showAnswer }) => (
|
{({ showAnswer, isTeacherMode }) => (
|
||||||
<div className="question-container">
|
<div className="question-container">
|
||||||
<div className="question content">
|
<div className="question content">
|
||||||
<div
|
<div
|
||||||
|
|
@ -60,7 +60,7 @@ const TrueFalseQuestionDisplay: React.FC = () => {
|
||||||
className="button-wrapper"
|
className="button-wrapper"
|
||||||
onClick={() => !showAnswer && handleOnClickAnswer(true)}
|
onClick={() => !showAnswer && handleOnClickAnswer(true)}
|
||||||
fullWidth
|
fullWidth
|
||||||
disabled={disableButton}
|
disabled={disableButton || isTeacherMode}
|
||||||
>
|
>
|
||||||
{showAnswer ? (
|
{showAnswer ? (
|
||||||
<div> {question.isTrue ? '✅' : '❌'}</div>
|
<div> {question.isTrue ? '✅' : '❌'}</div>
|
||||||
|
|
@ -86,7 +86,7 @@ const TrueFalseQuestionDisplay: React.FC = () => {
|
||||||
className="button-wrapper"
|
className="button-wrapper"
|
||||||
onClick={() => !showAnswer && handleOnClickAnswer(false)}
|
onClick={() => !showAnswer && handleOnClickAnswer(false)}
|
||||||
fullWidth
|
fullWidth
|
||||||
disabled={disableButton}
|
disabled={disableButton || isTeacherMode}
|
||||||
>
|
>
|
||||||
{showAnswer ? (
|
{showAnswer ? (
|
||||||
<div> {!question.isTrue ? '✅' : '❌'}</div>
|
<div> {!question.isTrue ? '✅' : '❌'}</div>
|
||||||
|
|
@ -120,7 +120,7 @@ const TrueFalseQuestionDisplay: React.FC = () => {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!showAnswer && submitAnswer && (
|
{!showAnswer && submitAnswer && !isTeacherMode && (
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
onClick={() =>
|
onClick={() =>
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ export const QuizContext = React.createContext<{
|
||||||
updateIndex: (questionId: number | null) => void; // Add a function to update the index
|
updateIndex: (questionId: number | null) => void; // Add a function to update the index
|
||||||
submitAnswer: (answer: AnswerType, idQuestion?: number) => void; // Updated submitAnswer signature
|
submitAnswer: (answer: AnswerType, idQuestion?: number) => void; // Updated submitAnswer signature
|
||||||
isQuestionSent: boolean;
|
isQuestionSent: boolean;
|
||||||
|
isTeacherMode: boolean; // Flag to indicate if the user is in teacher mode
|
||||||
|
setisTeacherMode: Dispatch<SetStateAction<boolean>>; // Setter for isTeacherMode
|
||||||
setIsQuestionSent: Dispatch<SetStateAction<boolean>>;
|
setIsQuestionSent: Dispatch<SetStateAction<boolean>>;
|
||||||
roomName: string;
|
roomName: string;
|
||||||
setRoomName: Dispatch<SetStateAction<string>>;
|
setRoomName: Dispatch<SetStateAction<string>>;
|
||||||
|
|
@ -36,6 +38,8 @@ export const QuizContext = React.createContext<{
|
||||||
index: null, // Default value for index
|
index: null, // Default value for index
|
||||||
updateIndex: () => {}, // Default no-op function
|
updateIndex: () => {}, // Default no-op function
|
||||||
submitAnswer: () => {}, // Default no-op function
|
submitAnswer: () => {}, // Default no-op function
|
||||||
|
isTeacherMode: false,
|
||||||
|
setisTeacherMode: () => {}, // Default no-op function
|
||||||
isQuestionSent: false,
|
isQuestionSent: false,
|
||||||
setIsQuestionSent: () => {},
|
setIsQuestionSent: () => {},
|
||||||
username: '', // Default value for username
|
username: '', // Default value for username
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,9 @@ export const QuizProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||||
|
|
||||||
const [isQuestionSent, setIsQuestionSent] = useState(false);
|
const [isQuestionSent, setIsQuestionSent] = useState(false);
|
||||||
|
|
||||||
|
const [isTeacherMode, setisTeacherMode] = useState(false);
|
||||||
|
|
||||||
|
|
||||||
const [username, setUsername] = useState<string>(ApiService.getUsername());
|
const [username, setUsername] = useState<string>(ApiService.getUsername());
|
||||||
|
|
||||||
const [roomName, setRoomName] = useState<string>(''); // Add roomName state
|
const [roomName, setRoomName] = useState<string>(''); // Add roomName state
|
||||||
|
|
@ -78,6 +81,8 @@ export const QuizProvider: React.FC<{ children: React.ReactNode }> = ({ children
|
||||||
submitAnswer, // Expose submitAnswer in the context
|
submitAnswer, // Expose submitAnswer in the context
|
||||||
isQuestionSent,
|
isQuestionSent,
|
||||||
setIsQuestionSent,
|
setIsQuestionSent,
|
||||||
|
isTeacherMode,
|
||||||
|
setisTeacherMode,
|
||||||
username,
|
username,
|
||||||
setUsername,
|
setUsername,
|
||||||
roomName,
|
roomName,
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ const ManageRoom: React.FC = () => {
|
||||||
setQuestions,
|
setQuestions,
|
||||||
index,
|
index,
|
||||||
updateIndex,
|
updateIndex,
|
||||||
|
setisTeacherMode,
|
||||||
} = useQuizContext();
|
} = useQuizContext();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -54,7 +55,6 @@ const ManageRoom: React.FC = () => {
|
||||||
console.log(`!quizStarted: returning.... `);
|
console.log(`!quizStarted: returning.... `);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (quizMode === 'teacher') {
|
if (quizMode === 'teacher') {
|
||||||
webSocketService.nextQuestion({
|
webSocketService.nextQuestion({
|
||||||
roomName: formattedRoomName,
|
roomName: formattedRoomName,
|
||||||
|
|
@ -253,7 +253,7 @@ const ManageRoom: React.FC = () => {
|
||||||
}, [socket, index, questions]);
|
}, [socket, index, questions]);
|
||||||
|
|
||||||
const nextQuestion = () => {
|
const nextQuestion = () => {
|
||||||
if (!questions || !index || !quiz?.content) return;
|
if (!questions || index == null || !quiz?.content) return;
|
||||||
|
|
||||||
const nextQuestionIndex = index +1;
|
const nextQuestionIndex = index +1;
|
||||||
|
|
||||||
|
|
@ -301,6 +301,7 @@ const ManageRoom: React.FC = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
updateIndex(0);
|
updateIndex(0);
|
||||||
|
setisTeacherMode(true);
|
||||||
webSocketService.nextQuestion({roomName: formattedRoomName, questions: questions, questionIndex: 0, isLaunch: true});
|
webSocketService.nextQuestion({roomName: formattedRoomName, questions: questions, questionIndex: 0, isLaunch: true});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -312,6 +313,7 @@ const ManageRoom: React.FC = () => {
|
||||||
console.log('Error launching quiz (launchStudentMode). No questions found.');
|
console.log('Error launching quiz (launchStudentMode). No questions found.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
setisTeacherMode(false);
|
||||||
setQuestions(questions);
|
setQuestions(questions);
|
||||||
webSocketService.launchStudentModeQuiz(formattedRoomName, questions);
|
webSocketService.launchStudentModeQuiz(formattedRoomName, questions);
|
||||||
};
|
};
|
||||||
|
|
@ -408,7 +410,7 @@ const ManageRoom: React.FC = () => {
|
||||||
{questions.length > 0 ? (
|
{questions.length > 0 ? (
|
||||||
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
<div style={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
<div className="title center-h-align mb-2">{quiz?.title}</div>
|
<div className="title center-h-align mb-2">{quiz?.title}</div>
|
||||||
{index && (
|
{index !== null && (
|
||||||
<strong className="number of questions">
|
<strong className="number of questions">
|
||||||
Question {index +1}/
|
Question {index +1}/
|
||||||
{questions?.length}
|
{questions?.length}
|
||||||
|
|
@ -428,7 +430,7 @@ const ManageRoom: React.FC = () => {
|
||||||
|
|
||||||
<div className="mb-2 flex-column-wrapper">
|
<div className="mb-2 flex-column-wrapper">
|
||||||
<div className="preview-and-result-container">
|
<div className="preview-and-result-container">
|
||||||
{index && (
|
{index !== null && (
|
||||||
<QuestionDisplay/>
|
<QuestionDisplay/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue