mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
refactor AnswerType
This commit is contained in:
parent
73e0326f44
commit
623b749e4f
12 changed files with 36 additions and 24 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { AnswerType } from "src/pages/Student/JoinRoom/JoinRoom";
|
||||
|
||||
export interface Answer {
|
||||
answer: string | number | boolean;
|
||||
answer: AnswerType;
|
||||
isCorrect: boolean;
|
||||
idQuestion: number;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { act } from 'react';
|
|||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { MultipleChoiceQuestion, parse } from 'gift-pegjs';
|
||||
import MultipleChoiceQuestionDisplay from 'src/components/QuestionsDisplay/MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
const questions = parse(
|
||||
`::Sample Question 1:: Question stem
|
||||
|
|
@ -21,7 +22,7 @@ describe('MultipleChoiceQuestionDisplay', () => {
|
|||
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
||||
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
||||
|
||||
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||
const handleOnSubmitAnswer = (answer: AnswerType) => {
|
||||
mockHandleOnSubmitAnswer(answer);
|
||||
setShowAnswerState(true);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import '@testing-library/jest-dom';
|
|||
import { MemoryRouter } from 'react-router-dom';
|
||||
import TrueFalseQuestionDisplay from 'src/components/QuestionsDisplay/TrueFalseQuestionDisplay/TrueFalseQuestionDisplay';
|
||||
import { parse, TrueFalseQuestion } from 'gift-pegjs';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
describe('TrueFalseQuestion Component', () => {
|
||||
const mockHandleSubmitAnswer = jest.fn();
|
||||
|
|
@ -16,7 +17,7 @@ describe('TrueFalseQuestion Component', () => {
|
|||
const TestWrapper = ({ showAnswer }: { showAnswer: boolean }) => {
|
||||
const [showAnswerState, setShowAnswerState] = useState(showAnswer);
|
||||
|
||||
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||
const handleOnSubmitAnswer = (answer: AnswerType) => {
|
||||
mockHandleSubmitAnswer(answer);
|
||||
setShowAnswerState(true);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,17 +4,18 @@ import '../questionStyle.css';
|
|||
import { Button } from '@mui/material';
|
||||
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
||||
import { MultipleChoiceQuestion } from 'gift-pegjs';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
interface Props {
|
||||
question: MultipleChoiceQuestion;
|
||||
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||
handleOnSubmitAnswer?: (answer: AnswerType) => void;
|
||||
showAnswer?: boolean;
|
||||
passedAnswer?: string | number | boolean;
|
||||
passedAnswer?: AnswerType;
|
||||
}
|
||||
|
||||
const MultipleChoiceQuestionDisplay: React.FC<Props> = (props) => {
|
||||
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } = props;
|
||||
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || '');
|
||||
const [answer, setAnswer] = useState<AnswerType>(passedAnswer || '');
|
||||
|
||||
|
||||
let disableButton = false;
|
||||
|
|
|
|||
|
|
@ -5,18 +5,19 @@ import { Button, TextField } from '@mui/material';
|
|||
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
||||
import { NumericalQuestion, SimpleNumericalAnswer, RangeNumericalAnswer, HighLowNumericalAnswer } from 'gift-pegjs';
|
||||
import { isSimpleNumericalAnswer, isRangeNumericalAnswer, isHighLowNumericalAnswer, isMultipleNumericalAnswer } from 'gift-pegjs/typeGuards';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
interface Props {
|
||||
question: NumericalQuestion;
|
||||
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||
handleOnSubmitAnswer?: (answer: AnswerType) => void;
|
||||
showAnswer?: boolean;
|
||||
passedAnswer?: string | number | boolean;
|
||||
passedAnswer?: AnswerType;
|
||||
}
|
||||
|
||||
const NumericalQuestionDisplay: React.FC<Props> = (props) => {
|
||||
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } =
|
||||
props;
|
||||
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || '');
|
||||
const [answer, setAnswer] = useState<AnswerType>(passedAnswer || '');
|
||||
const correctAnswers = question.choices;
|
||||
let correctAnswer = '';
|
||||
|
||||
|
|
|
|||
|
|
@ -5,13 +5,14 @@ import TrueFalseQuestionDisplay from './TrueFalseQuestionDisplay/TrueFalseQuesti
|
|||
import MultipleChoiceQuestionDisplay from './MultipleChoiceQuestionDisplay/MultipleChoiceQuestionDisplay';
|
||||
import NumericalQuestionDisplay from './NumericalQuestionDisplay/NumericalQuestionDisplay';
|
||||
import ShortAnswerQuestionDisplay from './ShortAnswerQuestionDisplay/ShortAnswerQuestionDisplay';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
// import useCheckMobileScreen from '../../services/useCheckMobileScreen';
|
||||
|
||||
interface QuestionProps {
|
||||
question: Question;
|
||||
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||
handleOnSubmitAnswer?: (answer: AnswerType) => void;
|
||||
showAnswer?: boolean;
|
||||
answer?: string | number | boolean;
|
||||
answer?: AnswerType;
|
||||
|
||||
}
|
||||
const QuestionDisplay: React.FC<QuestionProps> = ({
|
||||
|
|
|
|||
|
|
@ -3,19 +3,20 @@ import '../questionStyle.css';
|
|||
import { Button, TextField } from '@mui/material';
|
||||
import { FormattedTextTemplate } from '../../GiftTemplate/templates/TextTypeTemplate';
|
||||
import { ShortAnswerQuestion } from 'gift-pegjs';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
interface Props {
|
||||
question: ShortAnswerQuestion;
|
||||
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||
handleOnSubmitAnswer?: (answer: AnswerType) => void;
|
||||
showAnswer?: boolean;
|
||||
passedAnswer?: string | number | boolean;
|
||||
passedAnswer?: AnswerType;
|
||||
|
||||
}
|
||||
|
||||
const ShortAnswerQuestionDisplay: React.FC<Props> = (props) => {
|
||||
|
||||
const { question, showAnswer, handleOnSubmitAnswer, passedAnswer } = props;
|
||||
const [answer, setAnswer] = useState<string | number | boolean>(passedAnswer || '');
|
||||
const [answer, setAnswer] = useState<AnswerType>(passedAnswer || '');
|
||||
|
||||
useEffect(() => {
|
||||
if (passedAnswer !== undefined) {
|
||||
|
|
|
|||
|
|
@ -4,12 +4,13 @@ import '../questionStyle.css';
|
|||
import { Button } from '@mui/material';
|
||||
import { TrueFalseQuestion } from 'gift-pegjs';
|
||||
import { FormattedTextTemplate } from 'src/components/GiftTemplate/templates/TextTypeTemplate';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
interface Props {
|
||||
question: TrueFalseQuestion;
|
||||
handleOnSubmitAnswer?: (answer: string | number | boolean) => void;
|
||||
handleOnSubmitAnswer?: (answer: AnswerType) => void;
|
||||
showAnswer?: boolean;
|
||||
passedAnswer?: string | number | boolean;
|
||||
passedAnswer?: AnswerType;
|
||||
}
|
||||
|
||||
const TrueFalseQuestionDisplay: React.FC<Props> = (props) => {
|
||||
|
|
|
|||
|
|
@ -8,11 +8,12 @@ import { Button } from '@mui/material';
|
|||
import DisconnectButton from 'src/components/DisconnectButton/DisconnectButton';
|
||||
import { Question } from 'gift-pegjs';
|
||||
import { AnswerSubmissionToBackendType } from 'src/services/WebsocketService';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
interface StudentModeQuizProps {
|
||||
questions: QuestionType[];
|
||||
answers: AnswerSubmissionToBackendType[];
|
||||
submitAnswer: (_answer: string | number | boolean, _idQuestion: number) => void;
|
||||
submitAnswer: (_answer: AnswerType, _idQuestion: number) => void;
|
||||
disconnectWebSocket: () => void;
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
|||
//Ajouter type AnswerQuestionType en remplacement de QuestionType
|
||||
const [questionInfos, setQuestion] = useState<QuestionType>(questions[0]);
|
||||
const [isAnswerSubmitted, setIsAnswerSubmitted] = useState(false);
|
||||
// const [answer, setAnswer] = useState<string | number | boolean>('');
|
||||
// const [answer, setAnswer] = useState<AnswerType>('');
|
||||
|
||||
|
||||
const previousQuestion = () => {
|
||||
|
|
@ -42,7 +43,7 @@ const StudentModeQuiz: React.FC<StudentModeQuizProps> = ({
|
|||
setQuestion(questions[Number(questionInfos.question?.id)]);
|
||||
};
|
||||
|
||||
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||
const handleOnSubmitAnswer = (answer: AnswerType) => {
|
||||
const idQuestion = Number(questionInfos.question.id) || -1;
|
||||
submitAnswer(answer, idQuestion);
|
||||
setIsAnswerSubmitted(true);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
|||
interface TeacherModeQuizProps {
|
||||
questionInfos: QuestionType;
|
||||
answers: AnswerSubmissionToBackendType[];
|
||||
submitAnswer: (_answer: string | number | boolean, _idQuestion: number) => void;
|
||||
submitAnswer: (_answer: AnswerType, _idQuestion: number) => void;
|
||||
disconnectWebSocket: () => void;
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ const TeacherModeQuiz: React.FC<TeacherModeQuizProps> = ({
|
|||
setIsFeedbackDialogOpen(isAnswerSubmitted);
|
||||
}, [isAnswerSubmitted]);
|
||||
|
||||
const handleOnSubmitAnswer = (answer: string | number | boolean) => {
|
||||
const handleOnSubmitAnswer = (answer: AnswerType) => {
|
||||
const idQuestion = Number(questionInfos.question.id) || -1;
|
||||
submitAnswer(answer, idQuestion);
|
||||
// setAnswer(answer);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import QuestionDisplay from 'src/components/QuestionsDisplay/QuestionDisplay';
|
|||
import ApiService from '../../../services/ApiService';
|
||||
import { QuestionType } from 'src/Types/QuestionType';
|
||||
import { Button } from '@mui/material';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
|
||||
const ManageRoom: React.FC = () => {
|
||||
const navigate = useNavigate();
|
||||
|
|
@ -319,7 +320,7 @@ const ManageRoom: React.FC = () => {
|
|||
};
|
||||
|
||||
function checkIfIsCorrect(
|
||||
answer: string | number | boolean,
|
||||
answer: AnswerType,
|
||||
idQuestion: number,
|
||||
questions: QuestionType[]
|
||||
): boolean {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { io, Socket } from 'socket.io-client';
|
||||
import { AnswerType } from 'src/pages/Student/JoinRoom/JoinRoom';
|
||||
import { QuestionType } from 'src/Types/QuestionType';
|
||||
|
||||
// Must (manually) sync these types to server/socket/socket.js
|
||||
|
|
@ -6,14 +7,14 @@ import { QuestionType } from 'src/Types/QuestionType';
|
|||
export type AnswerSubmissionToBackendType = {
|
||||
roomName: string;
|
||||
username: string;
|
||||
answer: string | number | boolean;
|
||||
answer: AnswerType;
|
||||
idQuestion: number;
|
||||
};
|
||||
|
||||
export type AnswerReceptionFromBackendType = {
|
||||
idUser: string;
|
||||
username: string;
|
||||
answer: string | number | boolean;
|
||||
answer: AnswerType;
|
||||
idQuestion: number;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue