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
This commit is contained in:
@@ -131,6 +131,7 @@ const FillBlanks: React.FC<FillBlanksExercise & CommonProps> = ({
|
||||
<br />
|
||||
</p>
|
||||
));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [text, variant, renderLines, currentMCSelection]);
|
||||
|
||||
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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<number[]>(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 (
|
||||
|
||||
Reference in New Issue
Block a user