ENCOA-268

This commit is contained in:
Tiago Ribeiro
2024-12-12 16:14:54 +00:00
parent 6bb817f9af
commit 61d1bbbe13
8 changed files with 76 additions and 29 deletions

View File

@@ -14,6 +14,7 @@ import RenderAudioInstructionsPlayer from "./components/RenderAudioInstructionsP
import RenderAudioPlayer from "./components/RenderAudioPlayer";
import SectionNavbar from "./Navigation/SectionNavbar";
import ProgressButtons from "./components/ProgressButtons";
import PracticeModal from "@/components/PracticeModal";
const Listening: React.FC<ExamProps<ListeningExam>> = ({ exam, showSolutions = false, preview = false }) => {
@@ -83,8 +84,11 @@ const Listening: React.FC<ExamProps<ListeningExam>> = ({ exam, showSolutions = f
userSolutions: userSolutions.find((x) => x.exercise === exercise.id)?.solutions || [],
}))
const hasPractice = exercises.some(e => e.isPractice)
return (
<div className="flex flex-col gap-4">
<PracticeModal open={hasPractice} />
{formattedExercises.map(e => showSolutions
? renderSolution(e)
: (!startNow && !showPartDivider && !isBetweenParts && !showSolutions) && renderExercise(e, exam.id, registerSolution, preview))}
@@ -93,8 +97,6 @@ const Listening: React.FC<ExamProps<ListeningExam>> = ({ exam, showSolutions = f
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [partIndex, startNow, showPartDivider, isBetweenParts, showSolutions]);
const confirmFinishModule = (keepGoing?: boolean) => {
if (!keepGoing) {
setShowBlankModal(false);
@@ -129,12 +131,12 @@ const Listening: React.FC<ExamProps<ListeningExam>> = ({ exam, showSolutions = f
timesListened={timesListened}
setShowTextModal={setShowTextModal}
setTimesListened={setTimesListened}
// eslint-disable-next-line react-hooks/exhaustive-deps
// eslint-disable-next-line react-hooks/exhaustive-deps
/>, [partIndex, assignment, timesListened, setShowTextModal, setTimesListened])
const memoizedInstructions = useMemo(()=>
const memoizedInstructions = useMemo(() =>
<RenderAudioInstructionsPlayer />
, [])
, [])
return (
<>
@@ -180,9 +182,9 @@ const Listening: React.FC<ExamProps<ListeningExam>> = ({ exam, showSolutions = f
{/* Exercise renderer */}
<>
{(!startNow && !showPartDivider) && progressButtons}
{renderPartExercises}
{(!startNow && !showPartDivider && !isBetweenParts) && progressButtons}
{(!startNow && !showPartDivider) && progressButtons}
{renderPartExercises}
{(!startNow && !showPartDivider && !isBetweenParts) && progressButtons}
</>
</div>

View File

@@ -10,13 +10,14 @@ import { countExercises } from "@/utils/moduleUtils";
import PartDivider from "./Navigation/SectionDivider";
import ReadingPassage from "./components/ReadingPassage";
//import ReadingPassageModal from "./components/ReadingPassageModal";
import {calculateExerciseIndex} from "./utils/calculateExerciseIndex";
import { calculateExerciseIndex } from "./utils/calculateExerciseIndex";
import useExamNavigation from "./Navigation/useExamNavigation";
import { ExamProps } from "./types";
import useExamStore, { usePersistentExamStore } from "@/stores/exam";
import useExamTimer from "@/hooks/useExamTimer";
import SectionNavbar from "./Navigation/SectionNavbar";
import ProgressButtons from "./components/ProgressButtons";
import PracticeModal from "@/components/PracticeModal";
const Reading: React.FC<ExamProps<ReadingExam>> = ({ exam, showSolutions = false, preview = false }) => {
const updateTimers = useExamTimer(exam.module, preview || showSolutions);
@@ -50,6 +51,13 @@ const Reading: React.FC<ExamProps<ReadingExam>> = ({ exam, showSolutions = false
startNow
} = useExamNavigation({ exam, module: "reading", showBlankModal, setShowBlankModal, showSolutions, preview, disableBetweenParts: showSolutions });
const hasPractice = useMemo(() => {
if (partIndex > -1 && partIndex < exam.parts.length) {
return exam.parts[partIndex].exercises.some(e => e.isPractice)
}
return false
}, [partIndex, exam.parts])
useEffect(() => {
if (finalizeModule || timeIsUp) {
updateTimers();
@@ -130,7 +138,7 @@ const Reading: React.FC<ExamProps<ReadingExam>> = ({ exam, showSolutions = false
const progressButtons = useMemo(() =>
// Do not remove the ()=> in handle next
<ProgressButtons handlePrevious={previousExercise} handleNext={() => nextExercise()} />
, [nextExercise, previousExercise]);
, [nextExercise, previousExercise]);
return (
<>
@@ -146,6 +154,7 @@ const Reading: React.FC<ExamProps<ReadingExam>> = ({ exam, showSolutions = false
/>
</div> : (
<>
<PracticeModal key={partIndex} open={hasPractice} />
<div className="flex flex-col h-full w-full gap-8">
<BlankQuestionsModal isOpen={showBlankModal} onClose={confirmFinishModule} />
{/*<ReadingPassageModal text={exam.parts[partIndex].text} isOpen={showTextModal} onClose={() => setShowTextModal(false)} />*/}

View File

@@ -13,6 +13,7 @@ import useExamNavigation from "./Navigation/useExamNavigation";
import ProgressButtons from "./components/ProgressButtons";
import { calculateExerciseIndexSpeaking } from "./utils/calculateExerciseIndex";
import SectionNavbar from "./Navigation/SectionNavbar";
import PracticeModal from "@/components/PracticeModal";
const Speaking: React.FC<ExamProps<SpeakingExam>> = ({ exam, showSolutions = false, preview = false }) => {
@@ -33,6 +34,7 @@ const Speaking: React.FC<ExamProps<SpeakingExam>> = ({ exam, showSolutions = fal
const { finalizeModule, timeIsUp } = flags;
const timer = useRef(exam.minTimer - timeSpentCurrentModule / 60);
const hasPractice = useMemo(() => exam.exercises.some(e => e.isPractice), [exam.exercises])
const {
nextExercise, previousExercise,
@@ -110,6 +112,7 @@ const Speaking: React.FC<ExamProps<SpeakingExam>> = ({ exam, showSolutions = fal
onNext={handlePartDividerClick}
/> : (
<>
<PracticeModal open={hasPractice} />
{exam.exercises.length > 1 && <SectionNavbar
module="speaking"
sectionLabel="Part"

View File

@@ -11,6 +11,7 @@ import useExamTimer from "@/hooks/useExamTimer";
import useExamNavigation from "./Navigation/useExamNavigation";
import SectionNavbar from "./Navigation/SectionNavbar";
import ProgressButtons from "./components/ProgressButtons";
import PracticeModal from "@/components/PracticeModal";
const Writing: React.FC<ExamProps<WritingExam>> = ({ exam, showSolutions = false, preview = false }) => {
const updateTimers = useExamTimer(exam.module, preview || showSolutions);
@@ -27,6 +28,7 @@ const Writing: React.FC<ExamProps<WritingExam>> = ({ exam, showSolutions = false
} = !preview ? examState : persistentExamState;
const timer = useRef(exam.minTimer - timeSpentCurrentModule / 60);
const hasPractice = useMemo(() => exam.exercises.some(e => e.isPractice), [exam.exercises])
const { finalizeModule, timeIsUp } = flags;
const { nextDisabled } = navigation;
@@ -80,8 +82,8 @@ const Writing: React.FC<ExamProps<WritingExam>> = ({ exam, showSolutions = false
const progressButtons = useMemo(() =>
// Do not remove the ()=> in handle next
<ProgressButtons handlePrevious={previousExercise} handleNext={() => nextExercise()} nextDisabled={nextDisabled}/>
, [nextExercise, previousExercise, nextDisabled]);
<ProgressButtons handlePrevious={previousExercise} handleNext={() => nextExercise()} nextDisabled={nextDisabled} />
, [nextExercise, previousExercise, nextDisabled]);
return (
@@ -96,6 +98,7 @@ const Writing: React.FC<ExamProps<WritingExam>> = ({ exam, showSolutions = false
onNext={handlePartDividerClick}
/> : (
<div className="flex flex-col h-full w-full gap-8 items-center">
<PracticeModal open={hasPractice} />
{exam.exercises.length > 1 && <SectionNavbar
module="writing"
sectionLabel="Part"