From d3a37eed3edd07739d4398a79f90c158a4d17e14 Mon Sep 17 00:00:00 2001 From: Tiago Ribeiro Date: Fri, 23 Jun 2023 14:14:12 +0100 Subject: [PATCH] Redesigned the Record page along with solving some bugs on the FillBlanks --- src/components/Exercises/FillBlanks.tsx | 34 +-- src/components/Exercises/MatchSentences.tsx | 2 +- src/components/High/Layout.tsx | 5 +- src/components/Sidebar.tsx | 2 +- src/exams/Finish.tsx | 2 +- src/exams/Selection.tsx | 3 +- src/pages/exam.tsx | 15 +- src/pages/history.tsx | 153 ------------- src/pages/record.tsx | 239 ++++++++++++++++++++ src/utils/moduleUtils.ts | 4 + src/utils/score.ts | 30 ++- 11 files changed, 311 insertions(+), 178 deletions(-) delete mode 100644 src/pages/history.tsx create mode 100644 src/pages/record.tsx diff --git a/src/components/Exercises/FillBlanks.tsx b/src/components/Exercises/FillBlanks.tsx index d8ff1dff..f22a916b 100644 --- a/src/components/Exercises/FillBlanks.tsx +++ b/src/components/Exercises/FillBlanks.tsx @@ -17,7 +17,9 @@ interface WordsDrawerProps { function WordsDrawer({words, isOpen, blankId, previouslySelectedWord, onCancel, onAnswer}: WordsDrawerProps) { const [selectedWord, setSelectedWord] = useState(previouslySelectedWord); - useEffect(() => setSelectedWord(previouslySelectedWord), [previouslySelectedWord]); + useEffect(() => { + console.log({previouslySelectedWord}), setSelectedWord(previouslySelectedWord); + }, [previouslySelectedWord]); return ( <> @@ -79,11 +81,11 @@ export default function FillBlanks({ }: FillBlanksExercise & CommonProps) { const [answers, setAnswers] = useState<{id: string; solution: string}[]>(userSolutions); const [currentBlankId, setCurrentBlankId] = useState(); - const [blankSelectedWord, setBlankSelectedWord] = useState(); + const [isDrawerShowing, setIsDrawerShowing] = useState(false); useEffect(() => { - setBlankSelectedWord(currentBlankId ? answers.find((x) => x.id === currentBlankId)?.solution : undefined); - }, [answers, currentBlankId]); + setTimeout(() => setIsDrawerShowing(!!currentBlankId), 100); + }, [currentBlankId]); const calculateScore = () => { const total = text.match(/({{\d+}})/g)?.length || 0; @@ -120,17 +122,19 @@ export default function FillBlanks({ return ( <>
- ({word, isDisabled: allowRepetition ? false : answers.map((x) => x.solution).includes(word)}))} - previouslySelectedWord={blankSelectedWord} - isOpen={!!currentBlankId} - onCancel={() => setCurrentBlankId(undefined)} - onAnswer={(solution: string) => { - setAnswers((prev) => [...prev.filter((x) => x.id !== currentBlankId), {id: currentBlankId!, solution}]); - setCurrentBlankId(undefined); - }} - /> + {(!!currentBlankId || isDrawerShowing) && ( + ({word, isDisabled: allowRepetition ? false : answers.map((x) => x.solution).includes(word)}))} + previouslySelectedWord={currentBlankId ? answers.find((x) => x.id === currentBlankId)?.solution : undefined} + isOpen={isDrawerShowing} + onCancel={() => setCurrentBlankId(undefined)} + onAnswer={(solution: string) => { + setAnswers((prev) => [...prev.filter((x) => x.id !== currentBlankId), {id: currentBlankId!, solution}]); + setCurrentBlankId(undefined); + }} + /> + )} {prompt.split("\\n").map((line, index) => ( diff --git a/src/components/Exercises/MatchSentences.tsx b/src/components/Exercises/MatchSentences.tsx index fca9da97..95fdfe0a 100644 --- a/src/components/Exercises/MatchSentences.tsx +++ b/src/components/Exercises/MatchSentences.tsx @@ -53,7 +53,7 @@ export default function MatchSentences({id, options, type, prompt, sentences, us className={clsx( "bg-mti-green-ultralight text-mti-green hover:text-white hover:bg-mti-green w-8 h-8 rounded-full z-10", "transition duration-300 ease-in-out", - selectedQuestion === id && "!text-white bg-mti-green", + selectedQuestion === id && "!text-white !bg-mti-green", id, )}> {id} diff --git a/src/components/High/Layout.tsx b/src/components/High/Layout.tsx index 55b292ec..847b7b96 100644 --- a/src/components/High/Layout.tsx +++ b/src/components/High/Layout.tsx @@ -1,5 +1,6 @@ import {User} from "@/interfaces/user"; import clsx from "clsx"; +import {useRouter} from "next/router"; import Navbar from "../Navbar"; import Sidebar from "../Sidebar"; @@ -10,11 +11,13 @@ interface Props { } export default function Layout({user, children, className}: Props) { + const router = useRouter(); + return (
- +
- {selectedScore.total.toString().padStart(2, "0")} + {selectedScore.correct.toString().padStart(2, "0")} Correct
diff --git a/src/exams/Selection.tsx b/src/exams/Selection.tsx index 79d793f7..4973c654 100644 --- a/src/exams/Selection.tsx +++ b/src/exams/Selection.tsx @@ -9,6 +9,7 @@ import {totalExamsByModule} from "@/utils/stats"; import useStats from "@/hooks/useStats"; import Button from "@/components/Low/Button"; import {calculateAverageLevel} from "@/utils/score"; +import {sortByModuleName} from "@/utils/moduleUtils"; interface Props { user: User; @@ -164,7 +165,7 @@ export default function Selection({user, onStart}: Props) {