diff --git a/src/exams/Finish.tsx b/src/exams/Finish.tsx index e69de29b..86e53e75 100644 --- a/src/exams/Finish.tsx +++ b/src/exams/Finish.tsx @@ -0,0 +1,93 @@ +import ProfileLevel from "@/components/ProfileLevel"; +import {errorButtonStyle, infoButtonStyle} from "@/constants/buttonStyles"; +import {Module} from "@/interfaces"; +import {User} from "@/interfaces/user"; +import {ICONS} from "@/resources/modules"; +import {mdiArrowLeft, mdiArrowRight} from "@mdi/js"; +import Icon from "@mdi/react"; +import clsx from "clsx"; +import Link from "next/link"; +import router from "next/router"; + +interface Props { + user: User; + modules: Module[]; + scores: { + module?: Module; + correct: number; + total: number; + }[]; + onViewResults: () => void; +} + +export default function Finish({user, scores, modules, onViewResults}: Props) { + const renderModuleScore = (module: Module) => { + const moduleScores = scores.filter((x) => x.module === module); + if (moduleScores.length === 0) { + return <>0; + } + + return moduleScores.map((x, index) => ( + + {x.correct} / {x.total} + + )); + }; + + const renderModuleTotal = (module: Module) => { + const moduleScores = scores.filter((x) => x.module === module); + if (moduleScores.length === 0) { + return <>0; + } + + const total = moduleScores.reduce((accumulator, current) => accumulator + current.total, 0); + const correct = moduleScores.reduce((accumulator, current) => accumulator + current.correct, 0); + + return ( + + {correct} / {total} | {Math.floor((correct / total) * 100)}% + + ); + }; + + return ( +
+
+ +
+

You have finished the exam!

+
+ {modules.map((module) => ( +
+
+ + {module.toUpperCase()} +
+
{renderModuleScore(module)}
+
TOTAL: {renderModuleTotal(module)}
+
+ ))} +
+
+ + + + +
+
+
+
+ ); +} diff --git a/src/pages/exam/index.tsx b/src/pages/exam/index.tsx index 7b24c575..8543352a 100644 --- a/src/pages/exam/index.tsx +++ b/src/pages/exam/index.tsx @@ -17,6 +17,7 @@ import Listening from "@/exams/Listening"; import Writing from "@/exams/Writing"; import {ToastContainer} from "react-toastify"; import Link from "next/link"; +import Finish from "@/exams/Finish"; export default function Home() { const [selectedModules, setSelectedModules] = useState([]); @@ -67,20 +68,15 @@ export default function Home() { if (moduleIndex >= selectedModules.length) { return ( - <> - Finished!{" "} - - - - - + { + setShowSolutions(true); + setModuleIndex(0); + }} + scores={userSolutions.map((x) => ({...x.score, module: x.module}))} + /> ); } diff --git a/src/resources/modules.ts b/src/resources/modules.ts new file mode 100644 index 00000000..d5dfda5e --- /dev/null +++ b/src/resources/modules.ts @@ -0,0 +1,9 @@ +import {Module} from "@/interfaces"; +import {mdiAccountVoice, mdiBookOpen, mdiHeadphones, mdiPen} from "@mdi/js"; + +export const ICONS: {[key in Module]: string} = { + listening: mdiHeadphones, + reading: mdiBookOpen, + speaking: mdiAccountVoice, + writing: mdiPen, +};