Fixed some navigation issues and updated Listening
This commit is contained in:
@@ -17,10 +17,13 @@ type UseExamNavigation = (props: {
|
||||
showSolutions: boolean;
|
||||
preview: boolean;
|
||||
disableBetweenParts?: boolean;
|
||||
allPartExercisesRender?: boolean;
|
||||
modalBetweenParts?: boolean;
|
||||
}) => {
|
||||
showPartDivider: boolean;
|
||||
seenParts: Set<number>;
|
||||
isBetweenParts: boolean;
|
||||
startNow: boolean;
|
||||
nextExercise: (isBetweenParts?: boolean) => void;
|
||||
previousExercise: (isBetweenParts?: boolean) => void;
|
||||
setShowPartDivider: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
@@ -36,6 +39,8 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
showSolutions,
|
||||
preview,
|
||||
disableBetweenParts = false,
|
||||
allPartExercisesRender = false,
|
||||
modalBetweenParts = false,
|
||||
}) => {
|
||||
|
||||
const examState = useExamStore((state) => state);
|
||||
@@ -50,7 +55,10 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
dispatch,
|
||||
} = !preview ? examState : persistentExamState;
|
||||
|
||||
const [isBetweenParts, setIsBetweenParts] = useState(partIndex !== 0 && exerciseIndex == 0 && !disableBetweenParts);
|
||||
const [isBetweenParts, setIsBetweenParts] = useState(module === "reading"
|
||||
? (partIndex !== 0 && exerciseIndex === 0 && !disableBetweenParts)
|
||||
: (exerciseIndex === 0 && !disableBetweenParts)
|
||||
);
|
||||
const isPartExam = ["reading", "listening", "level"].includes(exam.module);
|
||||
|
||||
const [seenParts, setSeenParts] = useState<Set<number>>(
|
||||
@@ -63,6 +71,14 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
)
|
||||
);
|
||||
const [showPartDivider, setShowPartDivider] = useState<boolean>(hasDivider(exam, 0));
|
||||
const [startNow, setStartNow] = useState(!showPartDivider && !showSolutions);
|
||||
|
||||
// when navbar is used
|
||||
useEffect(()=> {
|
||||
if(startNow && partIndex !== 0) {
|
||||
setStartNow(false);
|
||||
}
|
||||
} , [partIndex, startNow])
|
||||
|
||||
useEffect(() => {
|
||||
if (!showSolutions && hasDivider(exam, isPartExam ? partIndex : exerciseIndex) && !seenParts.has(partIndex)) {
|
||||
@@ -95,14 +111,42 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
const nextPartExam = (keepGoing: boolean) => {
|
||||
const partExam = (exam as PartExam);
|
||||
|
||||
const reachedFinalExercise = exerciseIndex + 1 === partExam.parts[partIndex].exercises.length;
|
||||
const currentExercise = partExam.parts[partIndex].exercises[exerciseIndex];
|
||||
if (startNow) {
|
||||
setStartNow(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBetweenParts) {
|
||||
setIsBetweenParts(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (allPartExercisesRender) {
|
||||
if (partIndex < partExam.parts.length - 1) {
|
||||
if (!disableBetweenParts) setIsBetweenParts(true);
|
||||
setPartIndex(partIndex + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!answeredEveryQuestion(exam as PartExam, userSolutions) && !keepGoing && setShowBlankModal && !showSolutions && !preview) {
|
||||
if (modalKwargs) modalKwargs();
|
||||
setShowBlankModal(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (preview) {
|
||||
setPartIndex(0);
|
||||
} else if (!showSolutions) {
|
||||
dispatch({ type: "FINALIZE_MODULE", payload: { updateTimers: true } });
|
||||
} else {
|
||||
dispatch({ type: "FINALIZE_MODULE_SOLUTIONS" });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const reachedFinalExercise = exerciseIndex + 1 === partExam.parts[partIndex].exercises.length;
|
||||
const currentExercise = partExam.parts[partIndex].exercises[exerciseIndex];
|
||||
|
||||
if (currentExercise.type === "multipleChoice") {
|
||||
const nextQuestionIndex = questionIndex + MC_PER_PAGE;
|
||||
if (nextQuestionIndex < currentExercise.questions!.length) {
|
||||
@@ -110,11 +154,19 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!reachedFinalExercise) {
|
||||
setExerciseIndex(exerciseIndex + 1);
|
||||
setQuestionIndex(0);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(modalBetweenParts);
|
||||
if (modalBetweenParts && !answeredEveryQuestion(exam as PartExam, userSolutions) && !keepGoing && setShowBlankModal && !showSolutions && !preview) {
|
||||
if (modalKwargs) modalKwargs();
|
||||
setShowBlankModal(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (partIndex < partExam.parts.length - 1) {
|
||||
if (!disableBetweenParts) setIsBetweenParts(true);
|
||||
@@ -124,37 +176,58 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
return;
|
||||
}
|
||||
|
||||
if (!answeredEveryQuestion(exam as PartExam, userSolutions) && !keepGoing && setShowBlankModal && !showSolutions && !preview) {
|
||||
if (modalKwargs) modalKwargs()
|
||||
|
||||
if (!modalBetweenParts && !answeredEveryQuestion(exam as PartExam, userSolutions) && !keepGoing && setShowBlankModal && !showSolutions && !preview) {
|
||||
if (modalKwargs) modalKwargs();
|
||||
setShowBlankModal(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (preview) {
|
||||
setPartIndex(0);
|
||||
setExerciseIndex(0);
|
||||
setQuestionIndex(0);
|
||||
}
|
||||
|
||||
if (!showSolutions) {
|
||||
} else if (!showSolutions) {
|
||||
dispatch({ type: "FINALIZE_MODULE", payload: { updateTimers: true } });
|
||||
} else {
|
||||
dispatch({ type: "FINALIZE_MODULE_SOLUTIONS" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const previousPartExam = () => {
|
||||
|
||||
if (partIndex === 0 && exerciseIndex === 0 && !startNow) {
|
||||
setStartNow(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!disableBetweenParts && isBetweenParts) {
|
||||
setIsBetweenParts(false);
|
||||
}
|
||||
|
||||
if (allPartExercisesRender) {
|
||||
if (isBetweenParts && partIndex !== 0) {
|
||||
setPartIndex(partIndex - 1);
|
||||
setIsBetweenParts(false);
|
||||
return;
|
||||
}
|
||||
if (disableBetweenParts) {
|
||||
if (partIndex !== 0) {
|
||||
setPartIndex(partIndex - 1);
|
||||
}
|
||||
} else {
|
||||
setIsBetweenParts(true);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const currentExercise = (exam as PartExam).parts[partIndex].exercises[exerciseIndex];
|
||||
if (currentExercise.type === "multipleChoice" && questionIndex > 0) {
|
||||
if (currentExercise.type === "multipleChoice" && questionIndex > 0 && !allPartExercisesRender) {
|
||||
setQuestionIndex(Math.max(0, questionIndex - MC_PER_PAGE));
|
||||
return;
|
||||
}
|
||||
|
||||
if (exerciseIndex === 0 && !disableBetweenParts) {
|
||||
setIsBetweenParts(true);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (exerciseIndex !== 0) {
|
||||
setExerciseIndex(exerciseIndex - 1);
|
||||
setQuestionIndex(0);
|
||||
@@ -222,6 +295,7 @@ const useExamNavigation: UseExamNavigation = ({
|
||||
setSeenParts,
|
||||
isBetweenParts,
|
||||
setIsBetweenParts,
|
||||
startNow
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user