Skip to content

Commit b1a1fd4

Browse files
committed
refactor(cmdline): inline commands used for getList (@fehmer)
1 parent 5d169e9 commit b1a1fd4

File tree

1 file changed

+48
-55
lines changed

1 file changed

+48
-55
lines changed

frontend/src/ts/commandline/lists.ts

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { Command, CommandsSubgroup } from "./types";
3232
import { buildCommandForConfigKey } from "./util";
3333
import { CommandlineConfigMetadataObject } from "./commandline-metadata";
3434
import { isAuthAvailable, isAuthenticated, signOut } from "../firebase";
35+
import { ConfigKey } from "@monkeytype/schemas/configs";
3536

3637
const challengesPromise = JSONData.getChallengeList();
3738
challengesPromise
@@ -44,37 +45,22 @@ challengesPromise
4445
);
4546
});
4647

47-
const languageCommand = buildCommandForConfigKey("language");
48-
const difficultyCommand = buildCommandForConfigKey("difficulty");
49-
const blindModeCommand = buildCommandForConfigKey("blindMode");
50-
const oppositeShiftModeCommand = buildCommandForConfigKey("oppositeShiftMode");
51-
const stopOnErrorCommand = buildCommandForConfigKey("stopOnError");
52-
const confidenceModeCommand = buildCommandForConfigKey("confidenceMode");
53-
const lazyModeCommand = buildCommandForConfigKey("lazyMode");
54-
const layoutCommand = buildCommandForConfigKey("layout");
55-
const showAverageCommand = buildCommandForConfigKey("showAverage");
56-
const showPbCommand = buildCommandForConfigKey("showPb");
57-
const keymapLayoutCommand = buildCommandForConfigKey("keymapLayout");
58-
const customThemeCommand = buildCommandForConfigKey("customTheme");
59-
const adsCommand = buildCommandForConfigKey("ads");
60-
const minSpeedCommand = buildCommandForConfigKey("minWpm");
61-
const minAccCommand = buildCommandForConfigKey("minAcc");
62-
const paceCaretCommand = buildCommandForConfigKey("paceCaret");
63-
6448
export const commands: CommandsSubgroup = {
6549
title: "",
6650
list: [
6751
//result
6852
...ResultScreenCommands,
6953

7054
//test screen
71-
buildCommandForConfigKey("punctuation"),
72-
buildCommandForConfigKey("numbers"),
73-
buildCommandForConfigKey("mode"),
74-
buildCommandForConfigKey("time"),
75-
buildCommandForConfigKey("words"),
76-
buildCommandForConfigKey("quoteLength"),
77-
languageCommand,
55+
...buildCommands(
56+
"punctuation",
57+
"numbers",
58+
"mode",
59+
"time",
60+
"words",
61+
"quoteLength",
62+
"language",
63+
),
7864
{
7965
id: "changeCustomModeText",
8066
display: "Change custom text",
@@ -111,14 +97,14 @@ export const commands: CommandsSubgroup = {
11197

11298
//behavior
11399
...buildCommands(
114-
difficultyCommand,
100+
"difficulty",
115101
"quickRestart",
116102
"repeatQuotes",
117-
blindModeCommand,
103+
"blindMode",
118104
"alwaysShowWordsHistory",
119105
"singleListCommandLine",
120-
minSpeedCommand,
121-
minAccCommand,
106+
"minWpm",
107+
"minAcc",
122108
...MinBurstCommands,
123109
"britishEnglish",
124110
...FunboxCommands,
@@ -130,15 +116,15 @@ export const commands: CommandsSubgroup = {
130116
...buildCommands(
131117
"freedomMode",
132118
"strictSpace",
133-
oppositeShiftModeCommand,
134-
stopOnErrorCommand,
135-
confidenceModeCommand,
119+
"oppositeShiftMode",
120+
"stopOnError",
121+
"confidenceMode",
136122
"quickEnd",
137123
"indicateTypos",
138124
"compositionDisplay",
139125
"hideExtraLetters",
140-
lazyModeCommand,
141-
layoutCommand,
126+
"lazyMode",
127+
"layout",
142128
"codeUnindentOnBackspace",
143129
),
144130

@@ -154,7 +140,7 @@ export const commands: CommandsSubgroup = {
154140
...buildCommands(
155141
"smoothCaret",
156142
"caretStyle",
157-
paceCaretCommand,
143+
"paceCaret",
158144
"repeatedPace",
159145
"paceCaretStyle",
160146
),
@@ -184,14 +170,14 @@ export const commands: CommandsSubgroup = {
184170
"keymapStyle",
185171
"keymapLegendStyle",
186172
"keymapSize",
187-
keymapLayoutCommand,
173+
"keymapLayout",
188174
"keymapShowTopRow",
189175
),
190176

191177
//theme
192178
...buildCommands(
193179
...ThemesCommands,
194-
customThemeCommand,
180+
"customTheme",
195181

196182
...CustomThemesListCommands,
197183
"flipTestColors",
@@ -218,14 +204,14 @@ export const commands: CommandsSubgroup = {
218204
"showKeyTips",
219205
"showOutOfFocusWarning",
220206
"capsLockWarning",
221-
showAverageCommand,
222-
showPbCommand,
207+
"showAverage",
208+
"showPb",
223209
"monkeyPowerLevel",
224210
"monkey",
225211
),
226212

227213
//danger zone
228-
adsCommand,
214+
...buildCommands("ads"),
229215

230216
//other
231217
...LoadChallengeCommands,
@@ -381,29 +367,36 @@ export const commands: CommandsSubgroup = {
381367
],
382368
};
383369

370+
function findCommandById(key: ConfigKey): Command {
371+
const id = "change" + key.charAt(0).toUpperCase() + key.slice(1);
372+
const found = commands.list.find((it) => it.id === id);
373+
if (!found) throw new Error(`Cannot find command with id ${id}.`);
374+
return found;
375+
}
376+
384377
const lists = {
385-
keymapLayouts: keymapLayoutCommand.subgroup,
386-
enableAds: adsCommand.subgroup,
387-
customThemesList: customThemeCommand.subgroup,
378+
keymapLayouts: findCommandById("keymapLayout").subgroup,
379+
enableAds: findCommandById("ads").subgroup,
380+
customThemesList: findCommandById("customTheme").subgroup,
388381
themes: ThemesCommands[0]?.subgroup,
389382
loadChallenge: LoadChallengeCommands[0]?.subgroup,
390-
languages: languageCommand.subgroup,
391-
difficulty: difficultyCommand.subgroup,
392-
lazyMode: lazyModeCommand.subgroup,
393-
paceCaretMode: paceCaretCommand.subgroup,
394-
showAverage: showAverageCommand.subgroup,
395-
showPb: showPbCommand.subgroup,
396-
minWpm: minSpeedCommand.subgroup,
397-
minAcc: minAccCommand.subgroup,
383+
languages: findCommandById("language").subgroup,
384+
difficulty: findCommandById("difficulty").subgroup,
385+
lazyMode: findCommandById("lazyMode").subgroup,
386+
paceCaretMode: findCommandById("paceCaret").subgroup,
387+
showAverage: findCommandById("showAverage").subgroup,
388+
showPb: findCommandById("showPb").subgroup,
389+
minWpm: findCommandById("minWpm").subgroup,
390+
minAcc: findCommandById("minAcc").subgroup,
398391
minBurst: MinBurstCommands[0]?.subgroup,
399392
funbox: FunboxCommands[0]?.subgroup,
400-
confidenceMode: confidenceModeCommand.subgroup,
401-
stopOnError: stopOnErrorCommand.subgroup,
402-
layouts: layoutCommand.subgroup,
403-
oppositeShiftMode: oppositeShiftModeCommand.subgroup,
393+
confidenceMode: findCommandById("confidenceMode").subgroup,
394+
stopOnError: findCommandById("stopOnError").subgroup,
395+
layouts: findCommandById("layout").subgroup,
396+
oppositeShiftMode: findCommandById("oppositeShiftMode").subgroup,
404397
tags: TagsCommands[0]?.subgroup,
405398
resultSaving: ResultSavingCommands[0]?.subgroup,
406-
blindMode: blindModeCommand.subgroup,
399+
blindMode: findCommandById("blindMode").subgroup,
407400
};
408401

409402
export function doesListExist(listName: string): boolean {

0 commit comments

Comments
 (0)