From caddf87231ab400d952f0c6b383812bf93ae5408 Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Mon, 2 Sep 2024 22:18:33 +0100 Subject: [PATCH] Previous Level exams were being broken by the part divider changes, fixed it. --- src/components/Exercises/FillBlanks/index.tsx | 1 - src/components/Exercises/MatchSentences.tsx | 7 ++ src/components/Exercises/MultipleChoice.tsx | 3 +- src/components/Exercises/TrueFalse.tsx | 7 ++ src/components/Exercises/WriteBlanks.tsx | 7 +- src/components/Medium/ModuleTitle.tsx | 15 +-- src/components/Solutions/FillBlanks.tsx | 10 +- src/components/Solutions/MatchSentences.tsx | 12 +- src/components/Solutions/MultipleChoice.tsx | 1 - src/components/Solutions/TrueFalse.tsx | 12 +- src/components/Solutions/WriteBlanks.tsx | 12 +- src/exams/Level/PartDivider.tsx | 7 +- src/exams/Level/TextComponent.tsx | 24 ++-- src/exams/Level/index.tsx | 114 ++++++++---------- src/pages/(exam)/ExamPage.tsx | 2 +- src/utils/moduleUtils.ts | 4 +- 16 files changed, 142 insertions(+), 96 deletions(-) diff --git a/src/components/Exercises/FillBlanks/index.tsx b/src/components/Exercises/FillBlanks/index.tsx index 063ef0b1..9bca1c9d 100644 --- a/src/components/Exercises/FillBlanks/index.tsx +++ b/src/components/Exercises/FillBlanks/index.tsx @@ -228,7 +228,6 @@ const FillBlanks: React.FC = ({ className="max-w-[200px] w-full" disabled={ exam && exam.module === "level" && - typeof exam.parts[0].intro === "string" && partIndex === 0 && questionIndex === 0 } diff --git a/src/components/Exercises/MatchSentences.tsx b/src/components/Exercises/MatchSentences.tsx index 4f17c2c3..1b62cad6 100644 --- a/src/components/Exercises/MatchSentences.tsx +++ b/src/components/Exercises/MatchSentences.tsx @@ -67,6 +67,13 @@ export default function MatchSentences({id, options, type, prompt, sentences, us const [answers, setAnswers] = useState<{question: string; option: string}[]>(userSolutions); const hasExamEnded = useExamStore((state) => state.hasExamEnded); + + const setCurrentSolution = useExamStore((state) => state.setCurrentSolution); + + useEffect(() => { + setCurrentSolution({ exercise: id, solutions: answers, score: calculateScore(), type}); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [answers, setAnswers]) const handleDragEnd = (event: DragEndEvent) => { if (event.over && event.over.id.toString().startsWith("droppable")) { diff --git a/src/components/Exercises/MultipleChoice.tsx b/src/components/Exercises/MultipleChoice.tsx index 8cdc4f72..55816e07 100644 --- a/src/components/Exercises/MultipleChoice.tsx +++ b/src/components/Exercises/MultipleChoice.tsx @@ -174,8 +174,7 @@ export default function MultipleChoice({ id, prompt, type, questions, userSoluti
diff --git a/src/components/Solutions/MatchSentences.tsx b/src/components/Solutions/MatchSentences.tsx index c8f3b186..24502f31 100644 --- a/src/components/Solutions/MatchSentences.tsx +++ b/src/components/Solutions/MatchSentences.tsx @@ -8,6 +8,7 @@ import Icon from "@mdi/react"; import {Fragment} from "react"; import Button from "../Low/Button"; import Xarrow from "react-xarrows"; +import useExamStore from "@/stores/examStore"; function QuestionSolutionArea({ question, @@ -61,6 +62,8 @@ export default function MatchSentencesSolutions({ onNext, onBack, }: MatchSentencesExercise & CommonProps) { + const {questionIndex, setQuestionIndex, partIndex, exam} = useExamStore((state) => state); + const calculateScore = () => { const total = sentences.length; const correct = userSolutions.filter( @@ -112,7 +115,14 @@ export default function MatchSentencesSolutions({ color="purple" variant="outline" onClick={() => onBack({exercise: id, solutions: userSolutions, score: calculateScore(), type})} - className="max-w-[200px] w-full"> + className="max-w-[200px] w-full" + disabled={ + exam && + typeof partIndex !== "undefined" && + exam.module === "level" && + questionIndex === 0 && + partIndex === 0 + }> Back diff --git a/src/components/Solutions/MultipleChoice.tsx b/src/components/Solutions/MultipleChoice.tsx index 708c497f..0c28555d 100644 --- a/src/components/Solutions/MultipleChoice.tsx +++ b/src/components/Solutions/MultipleChoice.tsx @@ -164,7 +164,6 @@ export default function MultipleChoice({id, type, prompt, questions, userSolutio exam && typeof partIndex !== "undefined" && exam.module === "level" && - typeof exam.parts[0].intro === "string" && questionIndex === 0 && partIndex === 0 }> diff --git a/src/components/Solutions/TrueFalse.tsx b/src/components/Solutions/TrueFalse.tsx index a4ffc015..dc737c8c 100644 --- a/src/components/Solutions/TrueFalse.tsx +++ b/src/components/Solutions/TrueFalse.tsx @@ -4,10 +4,13 @@ import reactStringReplace from "react-string-replace"; import {CommonProps} from "."; import {Fragment} from "react"; import Button from "../Low/Button"; +import useExamStore from "@/stores/examStore"; type Solution = "true" | "false" | "not_given"; export default function TrueFalseSolution({prompt, type, id, questions, userSolutions, onNext, onBack}: TrueFalseExercise & CommonProps) { + const {questionIndex, setQuestionIndex, partIndex, exam} = useExamStore((state) => state); + const calculateScore = () => { const total = questions.length || 0; const correct = userSolutions.filter( @@ -121,7 +124,14 @@ export default function TrueFalseSolution({prompt, type, id, questions, userSolu color="purple" variant="outline" onClick={() => onBack({exercise: id, solutions: userSolutions, score: calculateScore(), type})} - className="max-w-[200px] w-full"> + className="max-w-[200px] w-full" + disabled={ + exam && + typeof partIndex !== "undefined" && + exam.module === "level" && + questionIndex === 0 && + partIndex === 0 + }> Back diff --git a/src/components/Solutions/WriteBlanks.tsx b/src/components/Solutions/WriteBlanks.tsx index 1772d703..e74bf1a0 100644 --- a/src/components/Solutions/WriteBlanks.tsx +++ b/src/components/Solutions/WriteBlanks.tsx @@ -8,6 +8,7 @@ import reactStringReplace from "react-string-replace"; import {CommonProps} from "."; import {toast} from "react-toastify"; import Button from "../Low/Button"; +import useExamStore from "@/stores/examStore"; function Blank({ id, @@ -71,6 +72,8 @@ export default function WriteBlanksSolutions({ onNext, onBack, }: WriteBlanksExercise & CommonProps) { + const {questionIndex, setQuestionIndex, partIndex, exam} = useExamStore((state) => state); + const calculateScore = () => { const total = text.match(/({{\d+}})/g)?.length || 0; const correct = userSolutions.filter( @@ -142,7 +145,14 @@ export default function WriteBlanksSolutions({ color="purple" variant="outline" onClick={() => onBack({exercise: id, solutions: userSolutions, score: calculateScore(), type})} - className="max-w-[200px] w-full"> + className="max-w-[200px] w-full" + disabled={ + exam && + typeof partIndex !== "undefined" && + exam.module === "level" && + questionIndex === 0 && + partIndex === 0 + }> Back diff --git a/src/exams/Level/PartDivider.tsx b/src/exams/Level/PartDivider.tsx index 480eeaad..f075f8c5 100644 --- a/src/exams/Level/PartDivider.tsx +++ b/src/exams/Level/PartDivider.tsx @@ -1,6 +1,7 @@ import Button from "@/components/Low/Button"; import { Module } from "@/interfaces"; import { LevelPart, UserSolution } from "@/interfaces/exam"; +import clsx from "clsx"; import { ReactNode } from "react"; import { BsBook, BsClipboard, BsHeadphones, BsMegaphone, BsPen } from "react-icons/bs"; @@ -21,10 +22,10 @@ const PartDivider: React.FC = ({ partIndex, part, onNext }) => { }; return ( -
+
{/** only level for now */} -
{moduleIcon["level"]}

{`Part ${partIndex + 1}`}

- {part.intro!.split('\\n\\n').map((x, index) =>

{x}

)} +
{moduleIcon["level"]}

{part.intro ? `Part ${partIndex + 1}` : "Placement Test"}

+ {part.intro && part.intro.split('\\n\\n').map((x, index) =>

{x}

)}
- - -
- )*/} - {exerciseIndex === -1 && partIndex === 0 && ( - - )} )}
diff --git a/src/pages/(exam)/ExamPage.tsx b/src/pages/(exam)/ExamPage.tsx index 079be535..c04a1c28 100644 --- a/src/pages/(exam)/ExamPage.tsx +++ b/src/pages/(exam)/ExamPage.tsx @@ -281,7 +281,7 @@ export default function ExamPage({page, user}: Props) { }, [statsAwaitingEvaluation]); useEffect(() => { - if (exam && exam.module === "level" && exam.parts[0].intro && !showSolutions) setBgColor("bg-ielts-level-light"); + if (exam && exam.module === "level" && !showSolutions) setBgColor("bg-ielts-level-light"); }, [exam, showSolutions, setBgColor]); const checkIfStatsHaveBeenEvaluated = (ids: string[]) => { diff --git a/src/utils/moduleUtils.ts b/src/utils/moduleUtils.ts index 59843034..251c6eb6 100644 --- a/src/utils/moduleUtils.ts +++ b/src/utils/moduleUtils.ts @@ -27,7 +27,9 @@ export const countExercises = (exercises: Exercise[]) => { if (e.type === "multipleChoice") return e.questions.length; if (e.type === "interactiveSpeaking") return e.prompts.length; if (e.type === "fillBlanks") return e.words.length; - + if (e.type === "writeBlanks") return e.solutions.length; + if (e.type === "matchSentences") return e.sentences.length; + if (e.type === "trueFalse") return e.questions.length; return 1; });