Added the speaking module to the application
This commit is contained in:
@@ -56,19 +56,6 @@ export default function Selection({user, onStart}: Props) {
|
||||
<Icon path={mdiHeadphones} color="white" size={3} />
|
||||
<span>Listening</span>
|
||||
</div>
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => toggleModule("speaking")}
|
||||
className={clsx(
|
||||
"flex flex-col gap-2 items-center justify-center",
|
||||
"border-ielts-speaking hover:bg-ielts-speaking text-white",
|
||||
"border-2 rounded-xl p-4 h-fit w-48 cursor-pointer",
|
||||
selectedModules.includes("speaking") ? "bg-ielts-speaking " : "bg-ielts-speaking-transparent ",
|
||||
)}>
|
||||
<Icon path={mdiAccountVoice} color="white" size={3} />
|
||||
<span>Speaking</span>
|
||||
</div>
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
@@ -82,6 +69,19 @@ export default function Selection({user, onStart}: Props) {
|
||||
<Icon path={mdiPen} color="white" size={3} />
|
||||
<span>Writing</span>
|
||||
</div>
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => toggleModule("speaking")}
|
||||
className={clsx(
|
||||
"flex flex-col gap-2 items-center justify-center",
|
||||
"border-ielts-speaking hover:bg-ielts-speaking text-white",
|
||||
"border-2 rounded-xl p-4 h-fit w-48 cursor-pointer",
|
||||
selectedModules.includes("speaking") ? "bg-ielts-speaking " : "bg-ielts-speaking-transparent ",
|
||||
)}>
|
||||
<Icon path={mdiAccountVoice} color="white" size={3} />
|
||||
<span>Speaking</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="w-full flex justify-between">
|
||||
<button onClick={() => router.push("/")} className={clsx("btn btn-wide gap-4 relative text-white", errorButtonStyle)}>
|
||||
|
||||
79
src/exams/Speaking.tsx
Normal file
79
src/exams/Speaking.tsx
Normal file
@@ -0,0 +1,79 @@
|
||||
import {renderExercise} from "@/components/Exercises";
|
||||
import {renderSolution} from "@/components/Solutions";
|
||||
import {infoButtonStyle} from "@/constants/buttonStyles";
|
||||
import {UserSolution, SpeakingExam} from "@/interfaces/exam";
|
||||
import {mdiArrowRight} from "@mdi/js";
|
||||
import Icon from "@mdi/react";
|
||||
import clsx from "clsx";
|
||||
import {Fragment, useEffect, useState} from "react";
|
||||
import {toast} from "react-toastify";
|
||||
|
||||
interface Props {
|
||||
exam: SpeakingExam;
|
||||
showSolutions?: boolean;
|
||||
onFinish: (userSolutions: UserSolution[]) => void;
|
||||
}
|
||||
|
||||
export default function Speaking({exam, showSolutions = false, onFinish}: Props) {
|
||||
const [exerciseIndex, setExerciseIndex] = useState(0);
|
||||
const [timer, setTimer] = useState<number>();
|
||||
const [userSolutions, setUserSolutions] = useState<UserSolution[]>([]);
|
||||
|
||||
useEffect(() => {
|
||||
setTimer(exam.minTimer * 60);
|
||||
const timerInterval = setInterval(() => setTimer((prev) => prev && prev - 1), 1000);
|
||||
|
||||
return () => {
|
||||
clearInterval(timerInterval);
|
||||
};
|
||||
}, [exam.minTimer]);
|
||||
|
||||
const nextExercise = (solution?: UserSolution) => {
|
||||
if (solution) {
|
||||
setUserSolutions((prev) => [...prev.filter((x) => x.id !== solution.id), solution]);
|
||||
}
|
||||
|
||||
if (exerciseIndex + 1 < exam.exercises.length) {
|
||||
setExerciseIndex((prev) => prev + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (solution) {
|
||||
onFinish([...userSolutions.filter((x) => x.id !== solution.id), solution].map((x) => ({...x, module: "speaking", exam: exam.id})));
|
||||
} else {
|
||||
onFinish(userSolutions.map((x) => ({...x, module: "speaking", exam: exam.id})));
|
||||
}
|
||||
};
|
||||
|
||||
const previousExercise = () => {
|
||||
setExerciseIndex((prev) => prev - 1);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-full h-full relative flex flex-col gap-8 items-center justify-center p-8 px-16 overflow-hidden">
|
||||
{timer && (
|
||||
<div className="absolute w-24 top-8 text-center right-8 font-semibold text-lg border-ielts-speaking border-2 p-2 rounded-xl bg-ielts-speaking-transparent text-white">
|
||||
{Math.floor(timer / 60) < 10 ? "0" : ""}
|
||||
{Math.floor(timer / 60)}:{timer % 60 < 10 ? "0" : ""}
|
||||
{timer % 60}
|
||||
</div>
|
||||
)}
|
||||
{exerciseIndex > -1 &&
|
||||
exerciseIndex < exam.exercises.length &&
|
||||
!showSolutions &&
|
||||
renderExercise(exam.exercises[exerciseIndex], nextExercise, previousExercise)}
|
||||
{exerciseIndex > -1 &&
|
||||
exerciseIndex < exam.exercises.length &&
|
||||
showSolutions &&
|
||||
renderSolution(exam.exercises[exerciseIndex], nextExercise, previousExercise)}
|
||||
{exerciseIndex === -1 && (
|
||||
<button className={clsx("btn btn-wide gap-4 relative text-white self-end", infoButtonStyle)} onClick={() => nextExercise()}>
|
||||
Next
|
||||
<div className="absolute right-4">
|
||||
<Icon path={mdiArrowRight} color="white" size={1} />
|
||||
</div>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user