Updated the eval calls to the backend, passed the navigation logic of level to useExamNavigation hook
This commit is contained in:
@@ -11,6 +11,7 @@ const MC_PER_PAGE = 2;
|
||||
type UseExamNavigation = (props: {
|
||||
exam: ModuleExam;
|
||||
module: Module;
|
||||
modalKwargs?: () => void;
|
||||
showBlankModal?: boolean;
|
||||
setShowBlankModal?: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
showSolutions: boolean;
|
||||
@@ -31,14 +32,15 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
exam,
|
||||
module,
|
||||
setShowBlankModal,
|
||||
modalKwargs,
|
||||
showSolutions,
|
||||
preview,
|
||||
disableBetweenParts = false,
|
||||
}) => {
|
||||
|
||||
const examState = useExamStore((state) => state);
|
||||
const persistentExamState = usePersistentExamStore((state) => state);
|
||||
|
||||
const persistentExamState = usePersistentExamStore((state) => state);
|
||||
|
||||
const {
|
||||
exerciseIndex, setExerciseIndex,
|
||||
partIndex, setPartIndex,
|
||||
@@ -101,11 +103,13 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentExercise.type === "multipleChoice" && questionIndex < currentExercise.questions.length - 1) {
|
||||
setQuestionIndex(questionIndex + MC_PER_PAGE);
|
||||
return;
|
||||
if (currentExercise.type === "multipleChoice") {
|
||||
const nextQuestionIndex = questionIndex + MC_PER_PAGE;
|
||||
if (nextQuestionIndex < currentExercise.questions!.length) {
|
||||
setQuestionIndex(nextQuestionIndex);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!reachedFinalExercise) {
|
||||
setExerciseIndex(exerciseIndex + 1);
|
||||
setQuestionIndex(0);
|
||||
@@ -121,6 +125,7 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
}
|
||||
|
||||
if (!answeredEveryQuestion(exam as PartExam, userSolutions) && !keepGoing && setShowBlankModal && !showSolutions && !preview) {
|
||||
if (modalKwargs) modalKwargs()
|
||||
setShowBlankModal(true);
|
||||
return;
|
||||
}
|
||||
@@ -134,20 +139,17 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
if (!showSolutions) {
|
||||
dispatch({ type: "FINALIZE_MODULE", payload: { updateTimers: true } });
|
||||
} else {
|
||||
dispatch({ type: "FINALIZE_MODULE_SOLUTIONS"});
|
||||
dispatch({ type: "FINALIZE_MODULE_SOLUTIONS" });
|
||||
}
|
||||
}
|
||||
|
||||
const previousPartExam = () => {
|
||||
if (partIndex !== 0) {
|
||||
setPartIndex(partIndex - 1);
|
||||
setExerciseIndex((exam as PartExam).parts[partIndex].exercises.length - 1);
|
||||
if (isBetweenParts) setIsBetweenParts(false);
|
||||
const currentExercise = (exam as PartExam).parts[partIndex].exercises[exerciseIndex];
|
||||
if (currentExercise.type === "multipleChoice" && questionIndex > 0) {
|
||||
setQuestionIndex(Math.max(0, questionIndex - MC_PER_PAGE));
|
||||
return;
|
||||
}
|
||||
|
||||
setQuestionIndex(0);
|
||||
|
||||
if (exerciseIndex === 0 && !disableBetweenParts) {
|
||||
setIsBetweenParts(true);
|
||||
return;
|
||||
@@ -155,7 +157,16 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
|
||||
if (exerciseIndex !== 0) {
|
||||
setExerciseIndex(exerciseIndex - 1);
|
||||
setQuestionIndex(0);
|
||||
}
|
||||
|
||||
if (partIndex !== 0) {
|
||||
setPartIndex(partIndex - 1);
|
||||
setExerciseIndex((exam as PartExam).parts[partIndex].exercises.length - 1);
|
||||
if (isBetweenParts) setIsBetweenParts(false);
|
||||
return;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
const nextExerciseOnlyExam = () => {
|
||||
@@ -166,7 +177,7 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
if (currentExercise.type === "interactiveSpeaking" && questionIndex < currentExercise.prompts.length - 1) {
|
||||
setQuestionIndex(questionIndex + 1)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!reachedFinalExercise) {
|
||||
setQuestionIndex(0);
|
||||
@@ -183,7 +194,7 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
if (!showSolutions) {
|
||||
dispatch({ type: "FINALIZE_MODULE", payload: { updateTimers: true } });
|
||||
} else {
|
||||
dispatch({ type: "FINALIZE_MODULE_SOLUTIONS"});
|
||||
dispatch({ type: "FINALIZE_MODULE_SOLUTIONS" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +205,7 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
if (currentExercise.type === "interactiveSpeaking" && questionIndex !== 0) {
|
||||
setQuestionIndex(questionIndex - 1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (exerciseIndex !== 0) {
|
||||
setExerciseIndex(exerciseIndex - 1);
|
||||
|
||||
Reference in New Issue
Block a user