Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@
"@tanstack/pacer-lite": "0.2.1",
"@tanstack/query-db-collection": "1.0.27",
"@tanstack/solid-db": "0.2.10",
"@tanstack/solid-devtools": "0.8.0",
"@tanstack/solid-form": "1.28.4",
"@tanstack/solid-hotkeys": "0.4.2",
"@tanstack/solid-hotkeys-devtools": "0.4.3",
"@tanstack/solid-query": "5.90.23",
"@tanstack/solid-query-devtools": "5.91.3",
"@tanstack/solid-table": "8.21.3",
Expand All @@ -60,7 +63,6 @@
"hangul-js": "0.2.6",
"howler": "2.2.3",
"idb": "8.0.3",
"konami": "1.7.0",
"lz-ts": "1.1.2",
"modern-screenshot": "4.6.8",
"object-hash": "3.0.0",
Expand Down
8 changes: 1 addition & 7 deletions frontend/src/html/pages/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@

<div class="tip">
tip: You can also change all these settings quickly using the command line (
<kbd>ctrl/cmd</kbd>
+
<kbd>shift</kbd>
+
<kbd>p</kbd>
or
<kbd>esc</kbd>
<mount data-component="commandlinehotkey"></mount>
)
</div>

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/ts/components/core/DevTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { JSXElement, lazy, onMount, Suspense } from "solid-js";
let DevComponents: (() => JSXElement) | undefined;

if (import.meta.env.DEV) {
const LazyQueryDevtools = lazy(async () =>
import("@tanstack/solid-query-devtools").then((m) => ({
default: m.SolidQueryDevtools,
const LazyTanstackDevtools = lazy(async () =>
import("./TanstackDevtools").then((m) => ({
default: m.TanStackDevtools,
})),
);
const LazyDevOptionsModal = lazy(async () =>
Expand All @@ -19,7 +19,7 @@ if (import.meta.env.DEV) {
default: () => {
onMount(() => {
m.attachDevtoolsOverlay({
defaultOpen: true,
defaultOpen: false,
noPadding: true,
});
});
Expand All @@ -31,7 +31,7 @@ if (import.meta.env.DEV) {

DevComponents = () => (
<Suspense>
<LazyQueryDevtools />
<LazyTanstackDevtools />
<LazyDevOptionsModal />
<LazySolidDevtoolsOverlay />
</Suspense>
Expand Down
23 changes: 23 additions & 0 deletions frontend/src/ts/components/core/TanstackDevtools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TanStackDevtools as TsDevTools } from "@tanstack/solid-devtools";
import { hotkeysDevtoolsPlugin } from "@tanstack/solid-hotkeys-devtools";
import { SolidQueryDevtoolsPanel } from "@tanstack/solid-query-devtools";
import { JSXElement } from "solid-js";

import { queryClient } from "../../queries";

export function TanStackDevtools(): JSXElement {
return (
<TsDevTools
plugins={[
{
id: "tanstack-query",
name: "TanStack Query",
render: () => <SolidQueryDevtoolsPanel client={queryClient} />,
defaultOpen: true,
},
hotkeysDevtoolsPlugin(),
]}
config={{ defaultOpen: false }}
/>
);
}
17 changes: 17 additions & 0 deletions frontend/src/ts/components/hotkeys/CommandlineHotkey.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { Show } from "solid-js";

import { hotkeys } from "../../states/hotkeys";
import { isFirefox } from "../../utils/misc";
import { Kbd } from "./Kbd";

export function CommandlineHotkey() {
return (
<>
<Kbd hotkey={hotkeys.commandline} />
<Show when={!isFirefox()}>
&nbsp;or&nbsp;
<Kbd hotkey="Mod+Shift+P" />
</Show>
</>
);
}
10 changes: 10 additions & 0 deletions frontend/src/ts/components/hotkeys/Kbd.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { formatWithLabels, Hotkey } from "@tanstack/solid-hotkeys";
import { JSXElement } from "solid-js";

export function Kbd(props: { hotkey: Hotkey }): JSXElement {
return (
<kbd>
{formatWithLabels(props.hotkey).toLowerCase().replace(/\+/g, " + ")}
</kbd>
);
}
16 changes: 16 additions & 0 deletions frontend/src/ts/components/hotkeys/QuickRestartHotkey.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { JSXElement, Show } from "solid-js";

import { getConfig } from "../../config/store";
import { hotkeys } from "../../states/hotkeys";
import { Kbd } from "./Kbd";

export function QuickRestartHotkey(): JSXElement {
return (
<Show
when={getConfig.quickRestart !== "off"}
fallback=<kbd>tab {">"} enter</kbd>
>
<Kbd hotkey={hotkeys.quickRestart} />
</Show>
);
}
29 changes: 4 additions & 25 deletions frontend/src/ts/components/layout/footer/Keytips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,10 @@ import { JSXElement, Show } from "solid-js";

import { getConfig } from "../../../config/store";
import { getFocus } from "../../../states/core";
import { Conditional } from "../../common/Conditional";
import { CommandlineHotkey } from "../../hotkeys/CommandlineHotkey";
import { QuickRestartHotkey } from "../../hotkeys/QuickRestartHotkey";

export function Keytips(): JSXElement {
const userAgent = window.navigator.userAgent.toLowerCase();
const modifierKey =
userAgent.includes("mac") && !userAgent.includes("firefox")
? "cmd"
: "ctrl";

const commandKey = (): string =>
getConfig.quickRestart === "esc" ? "tab" : "esc";

return (
<Show when={getConfig.showKeyTips}>
<div
Expand All @@ -22,22 +14,9 @@ export function Keytips(): JSXElement {
"opacity-0": getFocus(),
}}
>
<Conditional
if={getConfig.quickRestart === "off"}
then={
<>
<kbd>tab</kbd> + <kbd>enter</kbd> - restart test
</>
}
else={
<>
<kbd>{getConfig.quickRestart}</kbd> - restart test
</>
}
/>
<QuickRestartHotkey /> - restart test
<br />
<kbd>{commandKey()}</kbd> or <kbd>{modifierKey}</kbd> + <kbd>shift</kbd>{" "}
+ <kbd>p</kbd> - command line
<CommandlineHotkey /> - command line
</div>
</Show>
);
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/ts/components/layout/header/Logo.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { JSXElement } from "solid-js";

import {
restartTestEvent,
getActivePage,
getFocus,
} from "../../../states/core";
import { restartTestEvent } from "../../../events/test";
import { getActivePage, getFocus } from "../../../states/core";
import { cn } from "../../../utils/cn";
import { isDevEnvironment } from "../../../utils/env";

Expand Down
7 changes: 2 additions & 5 deletions frontend/src/ts/components/layout/header/Nav.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { useQuery } from "@tanstack/solid-query";
import { createMemo, JSXElement, Show } from "solid-js";

import { restartTestEvent } from "../../../events/test";
import { createEffectOn } from "../../../hooks/effects";
import {
prefetchAboutPage,
prefetchLeaderboardPage,
} from "../../../queries/prefetch";
import { getServerConfigurationQueryOptions } from "../../../queries/server-configuration";
import {
restartTestEvent,
getActivePage,
getFocus,
} from "../../../states/core";
import { getActivePage, getFocus } from "../../../states/core";
import {
getAccountButtonSpinner,
getAnimatedLevel,
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/ts/components/mount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { queryClient } from "../queries";
import { qsa } from "../utils/dom";
import { DevTools } from "./core/DevTools";
import { Theme } from "./core/Theme";
import { CommandlineHotkey } from "./hotkeys/CommandlineHotkey";
import { Footer } from "./layout/footer/Footer";
import { Header } from "./layout/header/Header";
import { Overlays } from "./layout/overlays/Overlays";
Expand All @@ -32,6 +33,7 @@ const components: Record<string, () => JSXElement> = {
theme: () => <Theme />,
header: () => <Header />,
devtools: () => <DevTools />,
commandlinehotkey: () => <CommandlineHotkey />,
};

function mountToMountpoint(name: string, component: () => JSXElement): void {
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/ts/components/pages/AboutPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { Button } from "../common/Button";
import { ChartJs } from "../common/ChartJs";
import { Fa } from "../common/Fa";
import { H2, H3 } from "../common/Headers";
import { CommandlineHotkey } from "../hotkeys/CommandlineHotkey";
import { QuickRestartHotkey } from "../hotkeys/QuickRestartHotkey";

export function AboutPage(): JSXElement {
const isOpen = () => getActivePage() === "about";
Expand Down Expand Up @@ -201,10 +203,8 @@ export function AboutPage(): JSXElement {
<section>
<H3 fa={{ icon: "fa-keyboard" }} text="keybinds" />
<p>
You can use <kbd>tab</kbd> and <kbd>enter</kbd> (or just{" "}
<kbd>tab</kbd> if you have quick tab mode enabled) to restart the
typing test. Open the command line by pressing <kbd>ctrl/cmd</kbd> +{" "}
<kbd>shift</kbd> + <kbd>p</kbd> or <kbd>esc</kbd> - there you can
You can use <QuickRestartHotkey /> to restart the typing test. Open
the command line by pressing <CommandlineHotkey /> - there you can
access all the functionality you need without touching your mouse.
</p>
</section>
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/ts/elements/modes-notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Format from "../singletons/format";
import { getActiveFunboxes, getActiveFunboxNames } from "../test/funbox/list";
import { escapeHTML, getMode2 } from "../utils/misc";
import { qsr } from "../utils/dom";
import { wordsHasNewline, wordsHasTab } from "../states/test";

configEvent.subscribe(({ key }) => {
const configKeys: ConfigEventKey[] = [
Expand Down Expand Up @@ -56,28 +57,28 @@ export async function update(): Promise<void> {
);
}

if (TestWords.hasTab) {
if (wordsHasTab()) {
if (Config.quickRestart === "esc") {
testModesNotice.appendHtml(
`<div class="textButton noInteraction"><i class="fas fa-long-arrow-alt-right"></i>shift + tab to open commandline</div>`,
`<div class="textButton noInteraction"><kbd>shift + tab</kbd> to open commandline</div>`,
);
testModesNotice.appendHtml(
`<div class="textButton noInteraction"><i class="fas fa-level-down-alt fa-rotate-90"></i>shift + esc to restart</div>`,
`<div class="textButton noInteraction"><kbd>esc</kbd> to restart</div>`,
);
}
if (Config.quickRestart === "tab") {
testModesNotice.appendHtml(
`<div class="textButton noInteraction"><i class="fas fa-level-down-alt fa-rotate-90"></i>shift + tab to restart</div>`,
`<div class="textButton noInteraction"><kbd>shift + tab</kbd> to restart</div>`,
);
}
}

if (
(TestWords.hasNewline || Config.funbox.includes("58008")) &&
(wordsHasNewline() || Config.funbox.includes("58008")) &&
Config.quickRestart === "enter"
) {
testModesNotice.appendHtml(
`<div class="textButton noInteraction"><i class="fas fa-level-down-alt fa-rotate-90"></i>shift + enter to restart</div>`,
`<div class="textButton noInteraction"><kbd>shift + enter</kbd> to restart</div>`,
);
}

Expand All @@ -87,7 +88,7 @@ export async function update(): Promise<void> {
testModesNotice.appendHtml(
`<div class="textButton noInteraction"><i class="fas fa-book"></i>${escapeHTML(
customTextName,
)} (shift + enter to save progress)</div>`,
)} (<kbd>shift + enter</kbd> to save progress)</div>`,
);
}

Expand All @@ -99,7 +100,7 @@ export async function update(): Promise<void> {

if (Config.mode === "zen") {
testModesNotice.appendHtml(
`<div class="textButton noInteraction"><i class="fas fa-poll"></i>shift + enter to finish zen </div>`,
`<div class="textButton noInteraction"><kbd>shift + enter</kbd> to finish zen </div>`,
);
}

Expand Down
50 changes: 0 additions & 50 deletions frontend/src/ts/event-handlers/global.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import * as Misc from "../utils/misc";
import * as PageTransition from "../legacy-states/page-transition";
import { Config } from "../config/store";
import * as TestWords from "../test/test-words";
import * as Commandline from "../commandline/commandline";
import { showErrorNotification } from "../states/notifications";
import { getActivePage } from "../states/core";
import { ModifierKeys } from "../constants/modifier-keys";
import { focusWords } from "../test/test-ui";
import * as TestLogic from "../test/test-logic";
import { navigate } from "../controllers/route-controller";
import { isInputElementFocused } from "../input/input-element";
import * as TestState from "../test/test-state";
import { isDevEnvironment } from "../utils/env";
Expand All @@ -35,52 +31,6 @@ document.addEventListener("keydown", (e) => {
}
}
}

if (
(e.key === "Escape" && Config.quickRestart !== "esc") ||
(e.key === "Tab" &&
Config.quickRestart === "esc" &&
!TestWords.hasTab &&
!e.shiftKey) ||
(e.key === "Tab" &&
Config.quickRestart === "esc" &&
TestWords.hasTab &&
e.shiftKey) ||
(e.key.toLowerCase() === "p" && (e.metaKey || e.ctrlKey) && e.shiftKey)
) {
const popupVisible = Misc.isAnyPopupVisible();
if (!popupVisible) {
e.preventDefault();
Commandline.show();
}
}

if (!isInputElementFocused()) {
const isInteractiveElement =
document.activeElement?.tagName === "INPUT" ||
document.activeElement?.tagName === "TEXTAREA" ||
document.activeElement?.tagName === "SELECT" ||
document.activeElement?.tagName === "BUTTON" ||
document.activeElement?.classList.contains("button") === true ||
document.activeElement?.classList.contains("textButton") === true;

if (
(e.key === "Tab" &&
Config.quickRestart === "tab" &&
!isInteractiveElement) ||
(e.key === "Escape" && Config.quickRestart === "esc") ||
(e.key === "Enter" &&
Config.quickRestart === "enter" &&
!isInteractiveElement)
) {
e.preventDefault();
if (getActivePage() === "test") {
TestLogic.restart({ isQuickRestart: !e.shiftKey });
} else {
void navigate("");
}
}
}
});

//stop space scrolling
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/ts/events/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createEvent } from "../hooks/createEvent";

export const restartTestEvent = createEvent<
{ isQuickRestart?: boolean } | undefined
>();
2 changes: 2 additions & 0 deletions frontend/src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ import "./ready";
import { setVersion } from "./states/core";
import { loadFromLocalStorage } from "./config/lifecycle";

import "./input/hotkeys";

// Lock Math.random
Object.defineProperty(Math, "random", {
value: Math.random,
Expand Down
Loading
Loading