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
8 changes: 6 additions & 2 deletions frontend/src/ts/commandline/commandline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
} from "../elements/input-validation";
import { isInputElementFocused } from "../input/input-element";
import { qs } from "../utils/dom";
import { ConfigKey } from "@monkeytype/schemas/configs";

type CommandlineMode = "search" | "input";
type InputModeParams = {
Expand Down Expand Up @@ -70,7 +71,10 @@ function addCommandlineBackground(): void {
}

type ShowSettings = {
subgroupOverride?: CommandsSubgroup | string;
subgroupOverride?:
| CommandsSubgroup
| CommandlineLists.ListsObjectKeys
| ConfigKey;
commandOverride?: string;
singleListOverride?: boolean;
};
Expand Down Expand Up @@ -102,7 +106,7 @@ export function show(
if (exists) {
Loader.show();
subgroupOverride = await CommandlineLists.getList(
settings.subgroupOverride as CommandlineLists.ListsObjectKeys,
settings.subgroupOverride,
);
Loader.hide();
} else {
Expand Down
99 changes: 42 additions & 57 deletions frontend/src/ts/commandline/lists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Command, CommandsSubgroup } from "./types";
import { buildCommandForConfigKey } from "./util";
import { CommandlineConfigMetadataObject } from "./commandline-metadata";
import { isAuthAvailable, isAuthenticated, signOut } from "../firebase";
import { ConfigKey } from "@monkeytype/schemas/configs";

const challengesPromise = JSONData.getChallengeList();
challengesPromise
Expand All @@ -44,37 +45,22 @@ challengesPromise
);
});

const languageCommand = buildCommandForConfigKey("language");
const difficultyCommand = buildCommandForConfigKey("difficulty");
const blindModeCommand = buildCommandForConfigKey("blindMode");
const oppositeShiftModeCommand = buildCommandForConfigKey("oppositeShiftMode");
const stopOnErrorCommand = buildCommandForConfigKey("stopOnError");
const confidenceModeCommand = buildCommandForConfigKey("confidenceMode");
const lazyModeCommand = buildCommandForConfigKey("lazyMode");
const layoutCommand = buildCommandForConfigKey("layout");
const showAverageCommand = buildCommandForConfigKey("showAverage");
const showPbCommand = buildCommandForConfigKey("showPb");
const keymapLayoutCommand = buildCommandForConfigKey("keymapLayout");
const customThemeCommand = buildCommandForConfigKey("customTheme");
const adsCommand = buildCommandForConfigKey("ads");
const minSpeedCommand = buildCommandForConfigKey("minWpm");
const minAccCommand = buildCommandForConfigKey("minAcc");
const paceCaretCommand = buildCommandForConfigKey("paceCaret");

export const commands: CommandsSubgroup = {
title: "",
list: [
//result
...ResultScreenCommands,

//test screen
buildCommandForConfigKey("punctuation"),
buildCommandForConfigKey("numbers"),
buildCommandForConfigKey("mode"),
buildCommandForConfigKey("time"),
buildCommandForConfigKey("words"),
buildCommandForConfigKey("quoteLength"),
languageCommand,
...buildCommands(
"punctuation",
"numbers",
"mode",
"time",
"words",
"quoteLength",
"language",
),
{
id: "changeCustomModeText",
display: "Change custom text",
Expand Down Expand Up @@ -111,14 +97,14 @@ export const commands: CommandsSubgroup = {

//behavior
...buildCommands(
difficultyCommand,
"difficulty",
"quickRestart",
"repeatQuotes",
blindModeCommand,
"blindMode",
"alwaysShowWordsHistory",
"singleListCommandLine",
minSpeedCommand,
minAccCommand,
"minWpm",
"minAcc",
...MinBurstCommands,
"britishEnglish",
...FunboxCommands,
Expand All @@ -130,15 +116,15 @@ export const commands: CommandsSubgroup = {
...buildCommands(
"freedomMode",
"strictSpace",
oppositeShiftModeCommand,
stopOnErrorCommand,
confidenceModeCommand,
"oppositeShiftMode",
"stopOnError",
"confidenceMode",
"quickEnd",
"indicateTypos",
"compositionDisplay",
"hideExtraLetters",
lazyModeCommand,
layoutCommand,
"lazyMode",
"layout",
"codeUnindentOnBackspace",
),

Expand All @@ -154,7 +140,7 @@ export const commands: CommandsSubgroup = {
...buildCommands(
"smoothCaret",
"caretStyle",
paceCaretCommand,
"paceCaret",
"repeatedPace",
"paceCaretStyle",
),
Expand Down Expand Up @@ -184,14 +170,14 @@ export const commands: CommandsSubgroup = {
"keymapStyle",
"keymapLegendStyle",
"keymapSize",
keymapLayoutCommand,
"keymapLayout",
"keymapShowTopRow",
),

//theme
...buildCommands(
...ThemesCommands,
customThemeCommand,
"customTheme",

...CustomThemesListCommands,
"flipTestColors",
Expand All @@ -218,14 +204,14 @@ export const commands: CommandsSubgroup = {
"showKeyTips",
"showOutOfFocusWarning",
"capsLockWarning",
showAverageCommand,
showPbCommand,
"showAverage",
"showPb",
"monkeyPowerLevel",
"monkey",
),

//danger zone
adsCommand,
...buildCommands("ads"),

//other
...LoadChallengeCommands,
Expand Down Expand Up @@ -382,40 +368,39 @@ export const commands: CommandsSubgroup = {
};

const lists = {
keymapLayouts: keymapLayoutCommand.subgroup,
enableAds: adsCommand.subgroup,
customThemesList: customThemeCommand.subgroup,
themes: ThemesCommands[0]?.subgroup,
loadChallenge: LoadChallengeCommands[0]?.subgroup,
languages: languageCommand.subgroup,
difficulty: difficultyCommand.subgroup,
lazyMode: lazyModeCommand.subgroup,
paceCaretMode: paceCaretCommand.subgroup,
showAverage: showAverageCommand.subgroup,
showPb: showPbCommand.subgroup,
minWpm: minSpeedCommand.subgroup,
minAcc: minAccCommand.subgroup,
minBurst: MinBurstCommands[0]?.subgroup,
funbox: FunboxCommands[0]?.subgroup,
confidenceMode: confidenceModeCommand.subgroup,
stopOnError: stopOnErrorCommand.subgroup,
layouts: layoutCommand.subgroup,
oppositeShiftMode: oppositeShiftModeCommand.subgroup,
tags: TagsCommands[0]?.subgroup,
resultSaving: ResultSavingCommands[0]?.subgroup,
blindMode: blindModeCommand.subgroup,
};

const subgroupByConfigKey = Object.fromEntries(
commands.list
.filter((it) => it.subgroup?.configKey !== undefined)
.map((it) => [it.subgroup?.configKey, it.subgroup]),
) as Record<string, CommandsSubgroup>;

export function doesListExist(listName: string): boolean {
if (subgroupByConfigKey[listName] !== undefined) {
return true;
}

return lists[listName as ListsObjectKeys] !== undefined;
}

export async function getList(
listName: ListsObjectKeys,
listName: ListsObjectKeys | ConfigKey,
): Promise<CommandsSubgroup> {
await Promise.allSettled([challengesPromise]);

const list = lists[listName];
const subGroup = subgroupByConfigKey[listName];
if (subGroup !== undefined) {
return subGroup;
}

const list = lists[listName as ListsObjectKeys];
if (!list) {
Notifications.add(`List not found: ${listName}`, -1);
throw new Error(`List ${listName} not found`);
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/ts/elements/modes-notice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function update(): Promise<void> {

if (Config.mode !== "zen" && !usingPolyglot) {
testModesNotice.appendHtml(
`<button class="textButton" commands="languages"><i class="fas fa-globe-americas"></i>${getLanguageDisplayString(
`<button class="textButton" commands="language"><i class="fas fa-globe-americas"></i>${getLanguageDisplayString(
Config.language,
Config.mode === "quote",
)}</button>`,
Expand Down Expand Up @@ -158,7 +158,7 @@ export async function update(): Promise<void> {
});

testModesNotice.appendHtml(
`<button class="textButton" commands="paceCaretMode"><i class="fas fa-tachometer-alt"></i>${
`<button class="textButton" commands="paceCaret"><i class="fas fa-tachometer-alt"></i>${
Config.paceCaret === "average"
? "average"
: Config.paceCaret === "pb"
Expand Down Expand Up @@ -278,7 +278,7 @@ export async function update(): Promise<void> {

if (Config.layout !== "default") {
testModesNotice.appendHtml(
`<button class="textButton" commands="layouts"><i class="fas fa-keyboard"></i>emulating ${Config.layout.replace(
`<button class="textButton" commands="layout"><i class="fas fa-keyboard"></i>emulating ${Config.layout.replace(
/_/g,
" ",
)}</button>`,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/event-handlers/footer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ document
}
setConfig("customTheme", true);
} else {
const subgroup = Config.customTheme ? "customThemesList" : "themes";
const subgroup = Config.customTheme ? "customTheme" : "themes";
Commandline.show({
subgroupOverride: subgroup,
});
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/event-handlers/keymap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import * as Commandline from "../commandline/commandline";

$("#keymap").on("click", ".r5 .layoutIndicator", async () => {
Commandline.show({
subgroupOverride: "keymapLayouts",
subgroupOverride: "keymapLayout",
});
});
4 changes: 3 additions & 1 deletion frontend/src/ts/event-handlers/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import * as PractiseWordsModal from "../modals/practise-words";
import { navigate } from "../controllers/route-controller";
import { getMode2 } from "../utils/misc";
import * as ShareTestSettingsPopup from "../modals/share-test-settings";
import { ConfigKey } from "@monkeytype/schemas/configs";
import { ListsObjectKeys } from "../commandline/lists";

$(".pageTest").on("click", "#testModesNotice .textButton", async (event) => {
const attr = $(event.currentTarget).attr("commands");
if (attr === undefined) return;
Commandline.show({ subgroupOverride: attr });
Commandline.show({ subgroupOverride: attr as ConfigKey | ListsObjectKeys });
});

$(".pageTest").on("click", "#testModesNotice .textButton", async (event) => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/modals/support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const modal = new AnimatedModal({
setup: async (modalEl): Promise<void> => {
modalEl.querySelector("button.ads")?.addEventListener("click", async () => {
Commandline.show(
{ subgroupOverride: "enableAds" },
{ subgroupOverride: "ads" },
{
modalChain: modal,
},
Expand Down