From b84d5fb6afbb7410246eb21b74597b2009fd0e00 Mon Sep 17 00:00:00 2001 From: Aliaksandr Radzivanovich Date: Thu, 7 Nov 2024 22:33:55 +0100 Subject: [PATCH] feat: rework the typing test page --- .../lib/TypingTestPage.test.tsx | 7 +-- .../lib/components/LineTemplate.module.less | 10 --- .../lib/components/LineTemplate.tsx | 27 +------- .../lib/components/Replay.tsx | 4 +- .../{Progress.tsx => ReplayProgress.tsx} | 6 +- .../lib/components/ReportScreen.tsx | 5 +- .../lib/components/SettingsScreen.tsx | 1 - .../lib/components/TestProgress.module.less | 18 ++++++ .../lib/components/TestProgress.tsx | 34 ++++++++++ .../lib/components/TestScreen.module.less | 2 + .../lib/components/TestScreen.tsx | 62 ++++++++++--------- .../lib/components/Toolbar.tsx | 22 +++---- .../settings/TypingSettings.module.less | 3 - .../settings/text/CommonWordsSettings.tsx | 4 -- .../page-typing-test/lib/session/session.ts | 12 +++- 15 files changed, 117 insertions(+), 100 deletions(-) rename packages/page-typing-test/lib/components/{Progress.tsx => ReplayProgress.tsx} (84%) create mode 100644 packages/page-typing-test/lib/components/TestProgress.module.less create mode 100644 packages/page-typing-test/lib/components/TestProgress.tsx delete mode 100644 packages/page-typing-test/lib/components/settings/TypingSettings.module.less diff --git a/packages/page-typing-test/lib/TypingTestPage.test.tsx b/packages/page-typing-test/lib/TypingTestPage.test.tsx index 965e9239d..d3dd2e356 100644 --- a/packages/page-typing-test/lib/TypingTestPage.test.tsx +++ b/packages/page-typing-test/lib/TypingTestPage.test.tsx @@ -4,10 +4,10 @@ import { KeyboardProvider } from "@keybr/keyboard"; import { FakePhoneticModel } from "@keybr/phonetic-model"; import { PhoneticModelLoader } from "@keybr/phonetic-model-loader"; import { FakeSettingsContext } from "@keybr/settings"; -import { fireEvent, render } from "@testing-library/react"; +import { render } from "@testing-library/react"; import { TypingTestPage } from "./TypingTestPage.tsx"; -test("render", async () => { +test("render", () => { PhoneticModelLoader.loader = FakePhoneticModel.loader; const r = render( @@ -20,8 +20,5 @@ test("render", async () => { , ); - fireEvent.click(await r.findByTitle("Settings", { exact: false })); - fireEvent.click(await r.findByTitle("Save settings", { exact: false })); - r.unmount(); }); diff --git a/packages/page-typing-test/lib/components/LineTemplate.module.less b/packages/page-typing-test/lib/components/LineTemplate.module.less index 299512952..37d9388bf 100644 --- a/packages/page-typing-test/lib/components/LineTemplate.module.less +++ b/packages/page-typing-test/lib/components/LineTemplate.module.less @@ -1,13 +1,3 @@ .line { - display: flex; - align-items: center; border-block-end: var(--separator-border); } - -.text { - flex: auto; -} - -.stats { - text-align: end; -} diff --git a/packages/page-typing-test/lib/components/LineTemplate.tsx b/packages/page-typing-test/lib/components/LineTemplate.tsx index 8ddac5e1d..0378db782 100644 --- a/packages/page-typing-test/lib/components/LineTemplate.tsx +++ b/packages/page-typing-test/lib/components/LineTemplate.tsx @@ -1,6 +1,5 @@ -import { formatDuration, Value } from "@keybr/widget"; import { memo, type ReactNode } from "react"; -import { type Progress, type SessionLine } from "../session/index.ts"; +import { type SessionLine } from "../session/index.ts"; import * as styles from "./LineTemplate.module.less"; export const LineTemplate = memo(function LineTemplate({ @@ -8,26 +7,6 @@ export const LineTemplate = memo(function LineTemplate({ progress, }: { readonly children: ReactNode; -} & SessionLine): ReactNode { - return ( -
-
{children}
-
{progress && }
-
- ); +} & SessionLine) { + return
{children}
; }); - -function Stats({ length, time, progress }: Progress): ReactNode { - return ( - <> - - {" / "} - - {" / "} - - - ); -} diff --git a/packages/page-typing-test/lib/components/Replay.tsx b/packages/page-typing-test/lib/components/Replay.tsx index 487d54395..2a859cd7d 100644 --- a/packages/page-typing-test/lib/components/Replay.tsx +++ b/packages/page-typing-test/lib/components/Replay.tsx @@ -12,8 +12,8 @@ import { Box, useDocumentVisibility } from "@keybr/widget"; import { type ReactNode, useEffect, useMemo, useState } from "react"; import { ReplayState, Session, type TestResult } from "../session/index.ts"; import { useCompositeSettings } from "../settings.ts"; -import { Progress } from "./Progress.tsx"; import * as styles from "./Replay.module.less"; +import { ReplayProgress } from "./ReplayProgress.tsx"; export function Replay({ result: { steps, events }, @@ -29,7 +29,7 @@ export function Replay({ ); return (
- + diff --git a/packages/page-typing-test/lib/components/Progress.tsx b/packages/page-typing-test/lib/components/ReplayProgress.tsx similarity index 84% rename from packages/page-typing-test/lib/components/Progress.tsx rename to packages/page-typing-test/lib/components/ReplayProgress.tsx index b248944b6..0af598331 100644 --- a/packages/page-typing-test/lib/components/Progress.tsx +++ b/packages/page-typing-test/lib/components/ReplayProgress.tsx @@ -8,9 +8,9 @@ import { import { useEffect, useState } from "react"; import { type ReplayState } from "../session/index.ts"; -export function Progress({ stepper }: { readonly stepper: ReplayState }) { +export function ReplayProgress({ stepper }: { readonly stepper: ReplayState }) { const { formatSpeed } = useFormatter(); - const { progress, time } = useProgress(stepper); + const { progress, time } = useReplayProgress(stepper); return ( { diff --git a/packages/page-typing-test/lib/components/ReportScreen.tsx b/packages/page-typing-test/lib/components/ReportScreen.tsx index 57d4f97bb..c01435da6 100644 --- a/packages/page-typing-test/lib/components/ReportScreen.tsx +++ b/packages/page-typing-test/lib/components/ReportScreen.tsx @@ -137,7 +137,6 @@ export function ReportScreen({ result }: { readonly result: TestResult }) {