ENCOA-253, ENCOA-248, ENCOA-246

This commit is contained in:
Carlos-Mesquita
2024-12-02 17:16:12 +00:00
parent cd14ac537d
commit 490c5ad7d3
8 changed files with 90 additions and 51 deletions

View File

@@ -92,7 +92,7 @@ const Level: React.FC<ExamProps<LevelExam>> = ({ exam, showSolutions = false, pr
const {
nextExercise, previousExercise,
showPartDivider, setShowPartDivider,
seenParts, setSeenParts, startNow
seenParts, setSeenParts, startNow, setStartNow
} = useExamNavigation(
{
exam, module: "level", showBlankModal: showQuestionsModal,
@@ -361,14 +361,14 @@ const Level: React.FC<ExamProps<LevelExam>> = ({ exam, showSolutions = false, pr
(!showPartDivider && !startNow) &&
<Timer minTimer={exam.minTimer} disableTimer={showSolutions || preview} standalone={true} />
}
{(showPartDivider || startNow) ?
{(showPartDivider || (startNow && partIndex === 0)) ?
<PartDivider
module="level"
sectionLabel="Part"
defaultTitle="Placement Test"
section={exam.parts[partIndex]}
sectionIndex={partIndex}
onNext={() => { setShowPartDivider(false); setBgColor("bg-white"); setSeenParts(prev => new Set(prev).add(partIndex)); }}
onNext={() => { setShowPartDivider(false); setStartNow(false); setBgColor("bg-white"); setSeenParts(prev => new Set(prev).add(partIndex)); }}
/> : (
<>
{exam.parts.length > 1 && <SectionNavbar

View File

@@ -29,6 +29,7 @@ type UseExamNavigation = (props: {
setShowPartDivider: React.Dispatch<React.SetStateAction<boolean>>;
setSeenParts: React.Dispatch<React.SetStateAction<Set<number>>>;
setIsBetweenParts: React.Dispatch<React.SetStateAction<boolean>>;
setStartNow: React.Dispatch<React.SetStateAction<boolean>>;
};
const useExamNavigation: UseExamNavigation = ({
@@ -50,8 +51,7 @@ const useExamNavigation: UseExamNavigation = ({
exerciseIndex, setExerciseIndex,
partIndex, setPartIndex,
questionIndex, setQuestionIndex,
userSolutions, setModuleIndex,
setBgColor,
userSolutions, setBgColor,
dispatch,
} = !preview ? examState : persistentExamState;
@@ -74,19 +74,34 @@ const useExamNavigation: UseExamNavigation = ({
const [startNow, setStartNow] = useState(!showPartDivider && !showSolutions);
// when navbar is used
useEffect(()=> {
if(startNow && !showPartDivider && partIndex !== 0) {
useEffect(() => {
if (startNow && !showPartDivider && partIndex !== 0) {
setStartNow(false);
}
} , [partIndex, startNow, showPartDivider])
}, [partIndex, startNow, showPartDivider])
useEffect(() => {
if (!showSolutions && hasDivider(exam, isPartExam ? partIndex : exerciseIndex) && !seenParts.has(partIndex)) {
setShowPartDivider(true);
if (
(
module === "level" ?
(startNow || hasDivider(exam, isPartExam ? partIndex : exerciseIndex))
:
(hasDivider(exam, isPartExam ? partIndex : exerciseIndex))
)
&& !showSolutions && !seenParts.has(partIndex)
) {
if (
// partIndex === 0 -> startNow
(module === "level" && (partIndex === 0 || hasDivider(exam, isPartExam ? partIndex : exerciseIndex))) ||
module !== "level"
) {
setShowPartDivider(true);
}
setBgColor(`bg-ielts-${module}-light`);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [partIndex]);
}, [partIndex, startNow]);
const nextExercise = (keepGoing: boolean = false) => {
scrollToTop();
@@ -160,7 +175,7 @@ const useExamNavigation: UseExamNavigation = ({
setQuestionIndex(0);
return;
}
if (modalBetweenParts && !seenParts.has(partIndex + 1) && !answeredEveryQuestionInPart(exam as PartExam, partIndex, userSolutions) && !keepGoing && setShowBlankModal && !showSolutions && !preview) {
if (modalKwargs) modalKwargs();
setShowBlankModal(true);
@@ -197,7 +212,7 @@ const useExamNavigation: UseExamNavigation = ({
const previousPartExam = () => {
if (!showPartDivider && partIndex === 0 && exerciseIndex === 0 && questionIndex === 0 && !startNow) {
setStartNow(true);
if (module !== "level") setStartNow(true);
return;
}
@@ -226,7 +241,7 @@ const useExamNavigation: UseExamNavigation = ({
setQuestionIndex(Math.max(0, questionIndex - MC_PER_PAGE));
return;
}
if (exerciseIndex !== 0) {
setExerciseIndex(exerciseIndex - 1);
setQuestionIndex(0);
@@ -294,7 +309,8 @@ const useExamNavigation: UseExamNavigation = ({
setSeenParts,
isBetweenParts,
setIsBetweenParts,
startNow
startNow,
setStartNow
};
}