Skip to content

Commit c852ff5

Browse files
fehmerMiodec
andauthored
refactor(hotkeys): use tanstack/hotkey (@fehmer, @d1rshan, @Miodec) (monkeytypegame#7691)
migrate quickRestart and commandline hotkeys to tanstack/hotkeys. Includes improvement of monkeytypegame#7690 --------- Co-authored-by: Miodec <jack@monkeytype.com>
1 parent f91eef3 commit c852ff5

31 files changed

Lines changed: 517 additions & 206 deletions

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@
3939
"@tanstack/pacer-lite": "0.2.1",
4040
"@tanstack/query-db-collection": "1.0.27",
4141
"@tanstack/solid-db": "0.2.10",
42+
"@tanstack/solid-devtools": "0.8.0",
4243
"@tanstack/solid-form": "1.28.4",
44+
"@tanstack/solid-hotkeys": "0.4.2",
45+
"@tanstack/solid-hotkeys-devtools": "0.4.3",
4346
"@tanstack/solid-query": "5.90.23",
4447
"@tanstack/solid-query-devtools": "5.91.3",
4548
"@tanstack/solid-table": "8.21.3",
@@ -60,7 +63,6 @@
6063
"hangul-js": "0.2.6",
6164
"howler": "2.2.3",
6265
"idb": "8.0.3",
63-
"konami": "1.7.0",
6466
"lz-ts": "1.1.2",
6567
"modern-screenshot": "4.6.8",
6668
"object-hash": "3.0.0",

frontend/src/html/pages/settings.html

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@
3838

3939
<div class="tip">
4040
tip: You can also change all these settings quickly using the command line (
41-
<kbd>ctrl/cmd</kbd>
42-
+
43-
<kbd>shift</kbd>
44-
+
45-
<kbd>p</kbd>
46-
or
47-
<kbd>esc</kbd>
41+
<mount data-component="commandlinehotkey"></mount>
4842
)
4943
</div>
5044

frontend/src/styles/test.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@
14241424

14251425
.textButton {
14261426
padding: 0.5em 1em;
1427+
align-items: center;
14271428
&.noInteraction {
14281429
pointer-events: none;
14291430
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { formatWithLabels, Hotkey } from "@tanstack/solid-hotkeys";
2+
import { JSXElement } from "solid-js";
3+
4+
type Props =
5+
| { hotkey: Hotkey; text?: undefined }
6+
| { hotkey?: undefined; text: string };
7+
8+
export function Kbd(props: Props): JSXElement {
9+
return (
10+
<kbd>
11+
{props.hotkey
12+
? formatWithLabels(props.hotkey).toLowerCase().replace(/\+/g, " + ")
13+
: props.text}
14+
</kbd>
15+
);
16+
}

frontend/src/ts/components/core/DevTools.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { JSXElement, lazy, onMount, Suspense } from "solid-js";
33
let DevComponents: (() => JSXElement) | undefined;
44

55
if (import.meta.env.DEV) {
6-
const LazyQueryDevtools = lazy(async () =>
7-
import("@tanstack/solid-query-devtools").then((m) => ({
8-
default: m.SolidQueryDevtools,
6+
const LazyTanstackDevtools = lazy(async () =>
7+
import("./TanstackDevtools").then((m) => ({
8+
default: m.TanStackDevtools,
99
})),
1010
);
1111
const LazyDevOptionsModal = lazy(async () =>
@@ -19,7 +19,7 @@ if (import.meta.env.DEV) {
1919
default: () => {
2020
onMount(() => {
2121
m.attachDevtoolsOverlay({
22-
defaultOpen: true,
22+
defaultOpen: false,
2323
noPadding: true,
2424
});
2525
});
@@ -31,7 +31,7 @@ if (import.meta.env.DEV) {
3131

3232
DevComponents = () => (
3333
<Suspense>
34-
<LazyQueryDevtools />
34+
<LazyTanstackDevtools />
3535
<LazyDevOptionsModal />
3636
<LazySolidDevtoolsOverlay />
3737
</Suspense>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { TanStackDevtools as TsDevTools } from "@tanstack/solid-devtools";
2+
import { hotkeysDevtoolsPlugin } from "@tanstack/solid-hotkeys-devtools";
3+
import { SolidQueryDevtoolsPanel } from "@tanstack/solid-query-devtools";
4+
import { JSXElement } from "solid-js";
5+
6+
import { queryClient } from "../../queries";
7+
8+
export function TanStackDevtools(): JSXElement {
9+
return (
10+
<TsDevTools
11+
plugins={[
12+
{
13+
id: "tanstack-query",
14+
name: "TanStack Query",
15+
render: () => <SolidQueryDevtoolsPanel client={queryClient} />,
16+
defaultOpen: true,
17+
},
18+
hotkeysDevtoolsPlugin(),
19+
]}
20+
config={{ defaultOpen: false }}
21+
/>
22+
);
23+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Show } from "solid-js";
2+
3+
import { hotkeys } from "../../states/hotkeys";
4+
import { isFirefox } from "../../utils/misc";
5+
import { Kbd } from "../common/Kbd";
6+
7+
export function CommandlineHotkey() {
8+
return (
9+
<>
10+
<Kbd hotkey={hotkeys.commandline} />
11+
<Show when={!isFirefox()}>
12+
&nbsp;or&nbsp;
13+
<Kbd hotkey="Mod+Shift+P" />
14+
</Show>
15+
</>
16+
);
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { Hotkey } from "@tanstack/solid-hotkeys";
2+
import { JSXElement } from "solid-js";
3+
4+
import { NoKey } from "../../input/hotkeys/utils";
5+
import { hotkeys } from "../../states/hotkeys";
6+
import { Kbd } from "../common/Kbd";
7+
8+
export function QuickRestartHotkey(): JSXElement {
9+
const props = (): { hotkey: Hotkey } | { text: string } =>
10+
hotkeys.quickRestart !== NoKey
11+
? { hotkey: hotkeys.quickRestart }
12+
: { text: "tab > enter" };
13+
14+
return <Kbd {...props()} />;
15+
}

frontend/src/ts/components/layout/footer/Keytips.tsx

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,27 @@ import { JSXElement, Show } from "solid-js";
22

33
import { getConfig } from "../../../config/store";
44
import { getFocus } from "../../../states/test";
5-
import { Conditional } from "../../common/Conditional";
5+
import { CommandlineHotkey } from "../../hotkeys/CommandlineHotkey";
6+
import { QuickRestartHotkey } from "../../hotkeys/QuickRestartHotkey";
67

78
export function Keytips(): JSXElement {
8-
const userAgent = window.navigator.userAgent.toLowerCase();
9-
const modifierKey =
10-
userAgent.includes("mac") && !userAgent.includes("firefox")
11-
? "cmd"
12-
: "ctrl";
13-
14-
const commandKey = (): string =>
15-
getConfig.quickRestart === "esc" ? "tab" : "esc";
16-
179
return (
1810
<Show when={getConfig.showKeyTips}>
1911
<div
20-
class="mb-8 text-center leading-loose transition-opacity"
12+
class="mb-8 flex flex-col items-center gap-2 transition-opacity"
2113
classList={{
2214
"opacity-0": getFocus(),
2315
}}
2416
>
25-
<Conditional
26-
if={getConfig.quickRestart === "off"}
27-
then={
28-
<>
29-
<kbd>tab</kbd> + <kbd>enter</kbd> - restart test
30-
</>
31-
}
32-
else={
33-
<>
34-
<kbd>{getConfig.quickRestart}</kbd> - restart test
35-
</>
36-
}
37-
/>
38-
<br />
39-
<kbd>{commandKey()}</kbd> or <kbd>{modifierKey}</kbd> + <kbd>shift</kbd>{" "}
40-
+ <kbd>p</kbd> - command line
17+
<div class="flex items-center gap-2">
18+
<QuickRestartHotkey />
19+
<span>- restart test</span>
20+
</div>
21+
22+
<div class="flex items-center gap-2">
23+
<CommandlineHotkey />
24+
<span>- command line</span>
25+
</div>
4126
</div>
4227
</Show>
4328
);

frontend/src/ts/components/mount.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { queryClient } from "../queries";
66
import { qsa } from "../utils/dom";
77
import { DevTools } from "./core/DevTools";
88
import { Theme } from "./core/Theme";
9+
import { CommandlineHotkey } from "./hotkeys/CommandlineHotkey";
910
import { Footer } from "./layout/footer/Footer";
1011
import { Header } from "./layout/header/Header";
1112
import { Overlays } from "./layout/overlays/Overlays";
@@ -34,6 +35,7 @@ const components: Record<string, () => JSXElement> = {
3435
header: () => <Header />,
3536
devtools: () => <DevTools />,
3637
testconfig: () => <TestConfig />,
38+
commandlinehotkey: () => <CommandlineHotkey />,
3739
};
3840

3941
function mountToMountpoint(name: string, component: () => JSXElement): void {

0 commit comments

Comments
 (0)