From 13c8fae588e410dcdf02706aa1ca171bee3e74c0 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Mon, 17 Apr 2023 18:42:28 +0100 Subject: [PATCH] Updated the timer to be on the Navbar, making it more mobile friendly --- src/components/LevelProgressBar.tsx | 2 +- src/components/Navbar.tsx | 13 +++++++++++-- src/exams/Listening.tsx | 19 +------------------ src/exams/Reading.tsx | 17 ----------------- src/exams/Selection.tsx | 8 ++++---- src/exams/Speaking.tsx | 17 ----------------- src/exams/Writing.tsx | 17 ----------------- src/pages/exam/index.tsx | 16 ++++++++++++++-- 8 files changed, 31 insertions(+), 78 deletions(-) diff --git a/src/components/LevelProgressBar.tsx b/src/components/LevelProgressBar.tsx index e2d2c3ad..e9bb630e 100644 --- a/src/components/LevelProgressBar.tsx +++ b/src/components/LevelProgressBar.tsx @@ -7,7 +7,7 @@ interface Props { progressBarWidth?: string; } -export default function LevelProgressBar({experience, className, progressBarWidth = "w-64"}: Props) { +export default function LevelProgressBar({experience, className, progressBarWidth = "w-32 md:w-64"}: Props) { const levelResult = levelCalculator(experience); return ( diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx index 0c621703..d58b2497 100644 --- a/src/components/Navbar.tsx +++ b/src/components/Navbar.tsx @@ -6,10 +6,11 @@ import {MenuItem} from "primereact/menuitem"; interface Props { profilePicture: string; + timer?: number; } /* eslint-disable @next/next/no-img-element */ -export default function Navbar({profilePicture}: Props) { +export default function Navbar({profilePicture, timer}: Props) { const router = useRouter(); const logout = async () => { @@ -49,9 +50,17 @@ export default function Navbar({profilePicture}: Props) { }, ]; + const end = timer && ( + + {Math.floor(timer / 60) < 10 ? "0" : ""} + {Math.floor(timer / 60)}:{timer % 60 < 10 ? "0" : ""} + {timer % 60} + + ); + return (
- +
); } diff --git a/src/exams/Listening.tsx b/src/exams/Listening.tsx index b80b5c0f..87561004 100644 --- a/src/exams/Listening.tsx +++ b/src/exams/Listening.tsx @@ -1,5 +1,5 @@ import {ListeningExam, UserSolution} from "@/interfaces/exam"; -import {useEffect, useState} from "react"; +import {useState} from "react"; import Icon from "@mdi/react"; import {mdiArrowRight} from "@mdi/js"; import clsx from "clsx"; @@ -16,18 +16,8 @@ interface Props { export default function Listening({exam, showSolutions = false, onFinish}: Props) { const [exerciseIndex, setExerciseIndex] = useState(-1); const [timesListened, setTimesListened] = useState(0); - const [timer, setTimer] = useState(); const [userSolutions, setUserSolutions] = useState([]); - 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]); @@ -78,13 +68,6 @@ export default function Listening({exam, showSolutions = false, onFinish}: Props return ( <>
- {timer && ( -
- {Math.floor(timer / 60) < 10 ? "0" : ""} - {Math.floor(timer / 60)}:{timer % 60 < 10 ? "0" : ""} - {timer % 60} -
- )} {renderAudioPlayer()} {exerciseIndex > -1 && exerciseIndex < exam.exercises.length && diff --git a/src/exams/Reading.tsx b/src/exams/Reading.tsx index 34721926..014a1262 100644 --- a/src/exams/Reading.tsx +++ b/src/exams/Reading.tsx @@ -76,18 +76,8 @@ function TextModal({isOpen, title, content, onClose}: {isOpen: boolean; title: s export default function Reading({exam, showSolutions = false, onFinish}: Props) { const [exerciseIndex, setExerciseIndex] = useState(-1); const [showTextModal, setShowTextModal] = useState(false); - const [timer, setTimer] = useState(); const [userSolutions, setUserSolutions] = useState([]); - 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]); @@ -131,13 +121,6 @@ export default function Reading({exam, showSolutions = false, onFinish}: Props) <> setShowTextModal(false)} />
- {timer && ( -
- {Math.floor(timer / 60) < 10 ? "0" : ""} - {Math.floor(timer / 60)}:{timer % 60 < 10 ? "0" : ""} - {timer % 60} -
- )} {exerciseIndex === -1 && renderText()} {exerciseIndex > -1 && exerciseIndex < exam.exercises.length && diff --git a/src/exams/Selection.tsx b/src/exams/Selection.tsx index 5b8389db..0104eda8 100644 --- a/src/exams/Selection.tsx +++ b/src/exams/Selection.tsx @@ -26,10 +26,10 @@ export default function Selection({user, onStart}: Props) { return ( <>
-
+
-
-
+
+
Speaking
-
+