mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-07 07:54:04 +08:00
refactor(commandline): change exec options to a single object
add commandlineModal parameter to open other modals in a chain add command.opensModal to avoid double hiding commandline
This commit is contained in:
parent
e933bbff73
commit
a8f6caebc9
13 changed files with 38 additions and 23 deletions
|
|
@ -410,8 +410,9 @@ function handleInputSubmit(): void {
|
|||
if (inputModeParams.command === null) {
|
||||
throw new Error("Can't handle input submit - command is null");
|
||||
}
|
||||
const value = inputValue;
|
||||
inputModeParams.command.exec?.(value);
|
||||
inputModeParams.command.exec?.({
|
||||
input: inputValue,
|
||||
});
|
||||
void AnalyticsController.log("usedCommandLine", {
|
||||
command: inputModeParams.command.id,
|
||||
});
|
||||
|
|
@ -444,11 +445,15 @@ async function runActiveCommand(): Promise<void> {
|
|||
await showCommands();
|
||||
await updateActiveCommand();
|
||||
} else {
|
||||
command.exec?.();
|
||||
command.exec?.({
|
||||
commandlineModal: modal,
|
||||
});
|
||||
const isSticky = command.sticky ?? false;
|
||||
if (!isSticky) {
|
||||
void AnalyticsController.log("usedCommandLine", { command: command.id });
|
||||
hide(true);
|
||||
if (!command.opensModal) {
|
||||
hide(true);
|
||||
}
|
||||
} else {
|
||||
await filterSubgroup();
|
||||
await showCommands();
|
||||
|
|
|
|||
|
|
@ -241,7 +241,7 @@ export const commands: MonkeyTypes.CommandsSubgroup = {
|
|||
},
|
||||
input: true,
|
||||
icon: "fa-tint",
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined) return;
|
||||
void UpdateConfig.setCustomLayoutfluid(
|
||||
input as MonkeyTypes.CustomLayoutFluidSpaces
|
||||
|
|
@ -308,7 +308,7 @@ export const commands: MonkeyTypes.CommandsSubgroup = {
|
|||
return Config.customBackground;
|
||||
},
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
UpdateConfig.setCustomBackground(input ?? "");
|
||||
},
|
||||
},
|
||||
|
|
@ -366,7 +366,7 @@ export const commands: MonkeyTypes.CommandsSubgroup = {
|
|||
icon: "fa-cog",
|
||||
alias: "import config",
|
||||
input: true,
|
||||
exec: async (input): Promise<void> => {
|
||||
exec: async ({ input }): Promise<void> => {
|
||||
if (input === undefined || input === "") return;
|
||||
try {
|
||||
await UpdateConfig.apply(JSON.parse(input));
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
defaultValue: (): string => {
|
||||
return Config.customBackgroundFilter[0].toString();
|
||||
},
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
const newFilters = Config.customBackgroundFilter;
|
||||
newFilters[0] = parseFloat(input);
|
||||
|
|
@ -27,7 +27,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
defaultValue: (): string => {
|
||||
return Config.customBackgroundFilter[1].toString();
|
||||
},
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
const newFilters = Config.customBackgroundFilter;
|
||||
newFilters[1] = parseFloat(input);
|
||||
|
|
@ -42,7 +42,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
defaultValue: (): string => {
|
||||
return Config.customBackgroundFilter[2].toString();
|
||||
},
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
const newFilters = Config.customBackgroundFilter;
|
||||
newFilters[2] = parseFloat(input);
|
||||
|
|
@ -57,7 +57,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
defaultValue: (): string => {
|
||||
return Config.customBackgroundFilter[3].toString();
|
||||
},
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
const newFilters = Config.customBackgroundFilter;
|
||||
newFilters[3] = parseFloat(input);
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ function update(fonts: MonkeyTypes.FontObject[]): void {
|
|||
hover: (): void => {
|
||||
UI.clearFontPreview();
|
||||
},
|
||||
exec: (name) => {
|
||||
if (name === undefined || name === "") return;
|
||||
UpdateConfig.setFontFamily(name.replace(/\s/g, "_"));
|
||||
exec: ({ input }) => {
|
||||
if (input === undefined || input === "") return;
|
||||
UpdateConfig.setFontFamily(input.replace(/\s/g, "_"));
|
||||
// Settings.groups.fontFamily.updateInput();
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const commands: MonkeyTypes.Command[] = [
|
|||
defaultValue: (): string => {
|
||||
return Config.fontSize.toString();
|
||||
},
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
UpdateConfig.setFontSize(parseFloat(input));
|
||||
},
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
display: "custom...",
|
||||
configValue: "custom",
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
UpdateConfig.setMinAccCustom(parseInt(input));
|
||||
UpdateConfig.setMinAcc("custom");
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
display: "fixed...",
|
||||
configValue: "fixed",
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
UpdateConfig.setMinBurst("fixed");
|
||||
const newVal = getTypingSpeedUnit(Config.typingSpeedUnit).toWpm(
|
||||
|
|
@ -32,7 +32,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
display: "flex...",
|
||||
configValue: "flex",
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
UpdateConfig.setMinBurst("flex");
|
||||
const newVal = getTypingSpeedUnit(Config.typingSpeedUnit).toWpm(
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
display: "custom...",
|
||||
configValue: "custom",
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
const newVal = getTypingSpeedUnit(Config.typingSpeedUnit).toWpm(
|
||||
parseInt(input)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ const subgroup: MonkeyTypes.CommandsSubgroup = {
|
|||
display: "custom...",
|
||||
configValue: "custom",
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
const newVal = getTypingSpeedUnit(Config.typingSpeedUnit).toWpm(
|
||||
parseInt(input)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import * as TagController from "../../controllers/tag-controller";
|
|||
import Config from "../../config";
|
||||
import * as PaceCaret from "../../test/pace-caret";
|
||||
import { isAuthenticated } from "../../firebase";
|
||||
import AnimatedModal from "../../utils/animated-modal";
|
||||
|
||||
const subgroup: MonkeyTypes.CommandsSubgroup = {
|
||||
title: "Change tags...",
|
||||
|
|
@ -39,6 +40,7 @@ function update(): void {
|
|||
display: "Create tag",
|
||||
icon: "fa-plus",
|
||||
shouldFocusTestUI: false,
|
||||
exec: ({ commandlineModal }): void => {
|
||||
EditTagsPopup.show(
|
||||
"add",
|
||||
undefined,
|
||||
|
|
@ -97,6 +99,8 @@ function update(): void {
|
|||
display: "Create tag",
|
||||
icon: "fa-plus",
|
||||
shouldFocusTestUI: false,
|
||||
opensModal: true,
|
||||
exec: ({ commandlineModal }): void => {
|
||||
EditTagsPopup.show(
|
||||
"add",
|
||||
undefined,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ const commands: MonkeyTypes.Command[] = [
|
|||
id: "changeTimeConfigCustom",
|
||||
display: "custom...",
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
UpdateConfig.setMode("time");
|
||||
UpdateConfig.setTimeConfig(parseInt(input));
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ const commands: MonkeyTypes.Command[] = [
|
|||
id: "changeWordCountCustom",
|
||||
display: "custom...",
|
||||
input: true,
|
||||
exec: (input): void => {
|
||||
exec: ({ input }): void => {
|
||||
if (input === undefined || input === "") return;
|
||||
UpdateConfig.setMode("words");
|
||||
UpdateConfig.setWordCount(parseInt(input));
|
||||
|
|
|
|||
8
frontend/src/ts/types/types.d.ts
vendored
8
frontend/src/ts/types/types.d.ts
vendored
|
|
@ -293,6 +293,11 @@ declare namespace MonkeyTypes {
|
|||
};
|
||||
};
|
||||
|
||||
type CommandExecOptions = {
|
||||
input?: string;
|
||||
commandlineModal?: unknown;
|
||||
};
|
||||
|
||||
type Command = {
|
||||
id: string;
|
||||
display: string;
|
||||
|
|
@ -306,11 +311,12 @@ declare namespace MonkeyTypes {
|
|||
input?: boolean;
|
||||
visible?: boolean;
|
||||
customStyle?: string;
|
||||
opensModal?: boolean;
|
||||
defaultValue?: () => string;
|
||||
configKey?: keyof SharedTypes.Config;
|
||||
configValue?: string | number | boolean | number[];
|
||||
configValueMode?: "include";
|
||||
exec?: (input?: string) => void;
|
||||
exec?: (options: CommandExecOptions) => void;
|
||||
hover?: () => void;
|
||||
available?: () => boolean;
|
||||
active?: () => boolean;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue