From ef32226c6ccf94638a90f5fe04c8c94c04ea9306 Mon Sep 17 00:00:00 2001 From: Carlos Mesquita Date: Tue, 27 Aug 2024 22:10:31 +0100 Subject: [PATCH] Previous commit solved completion but messed up question modal, patched that and added the condition to show the submission modal when all questions are awnswered --- src/components/Exercises/FillBlanks/index.tsx | 1 + src/components/Exercises/MultipleChoice.tsx | 12 +------ src/exams/Level/index.tsx | 31 +++++++++++++++---- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/components/Exercises/FillBlanks/index.tsx b/src/components/Exercises/FillBlanks/index.tsx index 96b3ae7e..063ef0b1 100644 --- a/src/components/Exercises/FillBlanks/index.tsx +++ b/src/components/Exercises/FillBlanks/index.tsx @@ -131,6 +131,7 @@ const FillBlanks: React.FC = ({

)); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [text, variant, renderLines, currentMCSelection]); diff --git a/src/components/Exercises/MultipleChoice.tsx b/src/components/Exercises/MultipleChoice.tsx index e03487ac..8cdc4f72 100644 --- a/src/components/Exercises/MultipleChoice.tsx +++ b/src/components/Exercises/MultipleChoice.tsx @@ -81,9 +81,7 @@ export default function MultipleChoice({ id, prompt, type, questions, userSoluti shuffles, hasExamEnded, partIndex, - userSolutions: storeUserSolutions, setQuestionIndex, - setUserSolutions, setCurrentSolution } = useExamStore((state) => state); @@ -91,14 +89,6 @@ export default function MultipleChoice({ id, prompt, type, questions, userSoluti const scrollToTop = () => Array.from(document.getElementsByTagName("body")).forEach((body) => body.scrollTo(0, 0)); - useEffect(() => { - setUserSolutions( - [...storeUserSolutions.filter((x) => x.exercise !== id), { - exercise: id, solutions: answers, score: calculateScore(), type - }]); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [answers]); - useEffect(() => { if (hasExamEnded) onNext({ exercise: id, solutions: answers, score: calculateScore(), type }); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -112,7 +102,7 @@ export default function MultipleChoice({ id, prompt, type, questions, userSoluti useEffect(() => { setCurrentSolution({ exercise: id, solutions: answers, score: calculateScore(), type, shuffleMaps: shuffleMaps }); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [answers]) + }, [answers, setAnswers]) const getShuffledSolution = (originalSolution: string, questionShuffleMap: ShuffleMap) => { for (const [newPosition, originalPosition] of Object.entries(questionShuffleMap.map)) { diff --git a/src/exams/Level/index.tsx b/src/exams/Level/index.tsx index 587c07ff..60e6bf65 100644 --- a/src/exams/Level/index.tsx +++ b/src/exams/Level/index.tsx @@ -51,12 +51,13 @@ export default function Level({ exam, showSolutions = false, onFinish, editing = setCurrentSolution } = useExamStore((state) => state); - const [multipleChoicesDone, setMultipleChoicesDone] = useState<{ id: string; amount: number }[]>([]); const [showQuestionsModal, setShowQuestionsModal] = useState(false); const [continueAnyways, setContinueAnyways] = useState(false); const [textRender, setTextRender] = useState(false); const [changedPrompt, setChangedPrompt] = useState(false); + const [nextExerciseCalled, setNextExerciseCalled] = useState(false); + const [currentSolutionSet, setCurrentSolutionSet] = useState(false); const [seenParts, setSeenParts] = useState(showSolutions ? exam.parts.map((_, index) => index) : [0]); @@ -80,6 +81,7 @@ export default function Level({ exam, showSolutions = false, onFinish, editing = useEffect(() => { if (typeof currentSolution !== "undefined") { setUserSolutions([...userSolutions.filter((x) => x.exercise !== currentSolution.exercise), { ...currentSolution, module: "level" as Module, exam: exam.id, shuffleMaps: exam.shuffle ? [...shuffles.find((x) => x.exerciseID == currentExercise?.id)?.shuffles!] : [] }]); + setCurrentSolutionSet(true); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [currentSolution, exam.id, exam.shuffle, shuffles, currentExercise]) @@ -118,8 +120,11 @@ export default function Level({ exam, showSolutions = false, onFinish, editing = // eslint-disable-next-line react-hooks/exhaustive-deps }, [partIndex, exerciseIndex, questionIndex]); + const next = () => { + setNextExerciseCalled(true); + } - const nextExercise = (solution?: UserSolution) => { + const nextExercise = () => { scrollToTop(); if (exerciseIndex + 1 < exam.parts[partIndex].exercises.length && !hasExamEnded) { @@ -155,13 +160,27 @@ export default function Level({ exam, showSolutions = false, onFinish, editing = return; } + if(partIndex + 1 === exam.parts.length && exerciseIndex === exam.parts[partIndex].exercises.length - 1 && !continueAnyways) { + modalKwargs(); + setShowQuestionsModal(true); + } + setHasExamEnded(false); if (typeof showSolutionsSave !== "undefined") { onFinish(showSolutionsSave); } else { onFinish(userSolutions); } - }; + } + + useEffect(() => { + if (nextExerciseCalled && currentSolutionSet) { + nextExercise(); + setNextExerciseCalled(false); + setCurrentSolutionSet(false); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [nextExerciseCalled, currentSolutionSet]) const previousExercise = (solution?: UserSolution) => { scrollToTop(); @@ -384,13 +403,13 @@ export default function Level({ exam, showSolutions = false, onFinish, editing = <> {exam.parts[partIndex].context && renderText()} {(showSolutions || editing) ? - renderSolution(currentExercise, nextExercise, previousExercise) - : - renderExercise(currentExercise, exam.id, nextExercise, previousExercise) + renderSolution(currentExercise, nextExercise, previousExercise) : + renderExercise(currentExercise, exam.id, next, previousExercise) } } ) + // eslint-disable-next-line react-hooks/exhaustive-deps }, [textRender, currentExercise, changedPrompt]); return (