Fix Finish page
This commit is contained in:
@@ -279,7 +279,7 @@ export default function ExamPage({
|
|||||||
};
|
};
|
||||||
|
|
||||||
userSolutions.forEach((x) => {
|
userSolutions.forEach((x) => {
|
||||||
if (x.isPractice === isPractice) {
|
if (isPractice ? x.isPractice : !x.isPractice) {
|
||||||
const examModule =
|
const examModule =
|
||||||
x.module ||
|
x.module ||
|
||||||
(x.type === "writing"
|
(x.type === "writing"
|
||||||
@@ -329,7 +329,7 @@ export default function ExamPage({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOnFocusLayerMouseEnter(() => () => setShowAbandonPopup(true));
|
setOnFocusLayerMouseEnter(() => () => setShowAbandonPopup(true));
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -355,107 +355,107 @@ export default function ExamPage({
|
|||||||
<>
|
<>
|
||||||
<ToastContainer />
|
<ToastContainer />
|
||||||
{user && (
|
{user && (
|
||||||
<>
|
<>
|
||||||
{/* Modules weren't yet set by an INIT_EXAM or INIT_SOLUTIONS dispatch, show Selection component*/}
|
{/* Modules weren't yet set by an INIT_EXAM or INIT_SOLUTIONS dispatch, show Selection component*/}
|
||||||
{selectedModules.length === 0 && (
|
{selectedModules.length === 0 && (
|
||||||
<Selection
|
<Selection
|
||||||
page={page}
|
page={page}
|
||||||
user={user!}
|
user={user!}
|
||||||
onStart={(
|
onStart={(
|
||||||
modules: Module[],
|
modules: Module[],
|
||||||
avoid: boolean,
|
avoid: boolean,
|
||||||
variant: Variant
|
variant: Variant
|
||||||
) => {
|
) => {
|
||||||
|
setModuleIndex(0);
|
||||||
|
setAvoidRepeated(avoid);
|
||||||
|
setSelectedModules(modules);
|
||||||
|
setVariant(variant);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{isFetchingExams && (
|
||||||
|
<div className="flex flex-grow flex-col items-center justify-center animate-pulse">
|
||||||
|
<span
|
||||||
|
className={`loading loading-infinity w-32 bg-ielts-${selectedModules[0]}`}
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
className={`font-bold text-2xl text-ielts-${selectedModules[0]}`}
|
||||||
|
>
|
||||||
|
Loading Exam ...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{moduleIndex === -1 && selectedModules.length !== 0 && (
|
||||||
|
<Finish
|
||||||
|
isLoading={userSolutions.some((s) => s.isDisabled)}
|
||||||
|
user={user!}
|
||||||
|
modules={selectedModules}
|
||||||
|
solutions={userSolutions}
|
||||||
|
assignment={assignment}
|
||||||
|
information={{
|
||||||
|
timeSpent,
|
||||||
|
inactivity,
|
||||||
|
}}
|
||||||
|
destination={destination}
|
||||||
|
onViewResults={(index?: number) => {
|
||||||
|
if (exams[0].module === "level") {
|
||||||
|
const levelExam = exams[0] as LevelExam;
|
||||||
|
const allExercises = levelExam.parts.flatMap(
|
||||||
|
(part) => part.exercises
|
||||||
|
);
|
||||||
|
const exerciseOrderMap = new Map(
|
||||||
|
allExercises.map((ex, index) => [ex.id, index])
|
||||||
|
);
|
||||||
|
const orderedSolutions = userSolutions
|
||||||
|
.slice()
|
||||||
|
.sort((a, b) => {
|
||||||
|
const indexA =
|
||||||
|
exerciseOrderMap.get(a.exercise) ?? Infinity;
|
||||||
|
const indexB =
|
||||||
|
exerciseOrderMap.get(b.exercise) ?? Infinity;
|
||||||
|
return indexA - indexB;
|
||||||
|
});
|
||||||
|
setUserSolutions(orderedSolutions);
|
||||||
|
} else {
|
||||||
|
setUserSolutions(userSolutions);
|
||||||
|
}
|
||||||
|
setShuffles([]);
|
||||||
|
if (index === undefined) {
|
||||||
|
setFlags({ reviewAll: true });
|
||||||
setModuleIndex(0);
|
setModuleIndex(0);
|
||||||
setAvoidRepeated(avoid);
|
setExam(exams[0]);
|
||||||
setSelectedModules(modules);
|
} else {
|
||||||
setVariant(variant);
|
setModuleIndex(index);
|
||||||
}}
|
setExam(exams[index]);
|
||||||
/>
|
}
|
||||||
)}
|
setShowSolutions(true);
|
||||||
{isFetchingExams && (
|
setQuestionIndex(0);
|
||||||
<div className="flex flex-grow flex-col items-center justify-center animate-pulse">
|
setExerciseIndex(0);
|
||||||
<span
|
setPartIndex(0);
|
||||||
className={`loading loading-infinity w-32 bg-ielts-${selectedModules[0]}`}
|
}}
|
||||||
|
scores={aggregateScoresByModule()}
|
||||||
|
practiceScores={aggregateScoresByModule(true)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{/* Exam is on going, display it and the abandon modal */}
|
||||||
|
{isExamLoaded && moduleIndex !== -1 && (
|
||||||
|
<>
|
||||||
|
{exam && CurrentExam && (
|
||||||
|
<CurrentExam exam={exam} showSolutions={showSolutions} />
|
||||||
|
)}
|
||||||
|
{!showSolutions && (
|
||||||
|
<AbandonPopup
|
||||||
|
isOpen={showAbandonPopup}
|
||||||
|
abandonPopupTitle="Leave Exercise"
|
||||||
|
abandonPopupDescription="Are you sure you want to leave the exercise? Your progress will be saved and this exam can be resumed on the Dashboard."
|
||||||
|
abandonConfirmButtonText="Confirm"
|
||||||
|
onAbandon={onAbandon}
|
||||||
|
onCancel={() => setShowAbandonPopup(false)}
|
||||||
/>
|
/>
|
||||||
<span
|
)}
|
||||||
className={`font-bold text-2xl text-ielts-${selectedModules[0]}`}
|
</>
|
||||||
>
|
)}
|
||||||
Loading Exam ...
|
</>
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{moduleIndex === -1 && selectedModules.length !== 0 && (
|
|
||||||
<Finish
|
|
||||||
isLoading={userSolutions.some((s) => s.isDisabled)}
|
|
||||||
user={user!}
|
|
||||||
modules={selectedModules}
|
|
||||||
solutions={userSolutions}
|
|
||||||
assignment={assignment}
|
|
||||||
information={{
|
|
||||||
timeSpent,
|
|
||||||
inactivity,
|
|
||||||
}}
|
|
||||||
destination={destination}
|
|
||||||
onViewResults={(index?: number) => {
|
|
||||||
if (exams[0].module === "level") {
|
|
||||||
const levelExam = exams[0] as LevelExam;
|
|
||||||
const allExercises = levelExam.parts.flatMap(
|
|
||||||
(part) => part.exercises
|
|
||||||
);
|
|
||||||
const exerciseOrderMap = new Map(
|
|
||||||
allExercises.map((ex, index) => [ex.id, index])
|
|
||||||
);
|
|
||||||
const orderedSolutions = userSolutions
|
|
||||||
.slice()
|
|
||||||
.sort((a, b) => {
|
|
||||||
const indexA =
|
|
||||||
exerciseOrderMap.get(a.exercise) ?? Infinity;
|
|
||||||
const indexB =
|
|
||||||
exerciseOrderMap.get(b.exercise) ?? Infinity;
|
|
||||||
return indexA - indexB;
|
|
||||||
});
|
|
||||||
setUserSolutions(orderedSolutions);
|
|
||||||
} else {
|
|
||||||
setUserSolutions(userSolutions);
|
|
||||||
}
|
|
||||||
setShuffles([]);
|
|
||||||
if (index === undefined) {
|
|
||||||
setFlags({ reviewAll: true });
|
|
||||||
setModuleIndex(0);
|
|
||||||
setExam(exams[0]);
|
|
||||||
} else {
|
|
||||||
setModuleIndex(index);
|
|
||||||
setExam(exams[index]);
|
|
||||||
}
|
|
||||||
setShowSolutions(true);
|
|
||||||
setQuestionIndex(0);
|
|
||||||
setExerciseIndex(0);
|
|
||||||
setPartIndex(0);
|
|
||||||
}}
|
|
||||||
scores={aggregateScoresByModule()}
|
|
||||||
practiceScores={aggregateScoresByModule(true)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
{/* Exam is on going, display it and the abandon modal */}
|
|
||||||
{isExamLoaded && moduleIndex !== -1 && (
|
|
||||||
<>
|
|
||||||
{exam && CurrentExam && (
|
|
||||||
<CurrentExam exam={exam} showSolutions={showSolutions} />
|
|
||||||
)}
|
|
||||||
{!showSolutions && (
|
|
||||||
<AbandonPopup
|
|
||||||
isOpen={showAbandonPopup}
|
|
||||||
abandonPopupTitle="Leave Exercise"
|
|
||||||
abandonPopupDescription="Are you sure you want to leave the exercise? Your progress will be saved and this exam can be resumed on the Dashboard."
|
|
||||||
abandonConfirmButtonText="Confirm"
|
|
||||||
onAbandon={onAbandon}
|
|
||||||
onCancel={() => setShowAbandonPopup(false)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user