From 1afca8204adf33ae1704c7bd9e5cd08e654a044f Mon Sep 17 00:00:00 2001 From: Varun Tiwari Date: Tue, 25 Oct 2022 17:08:57 +0530 Subject: [PATCH] Added commands to add/remove the current theme to favorites (#3682) varunKT001 * Added 'Add current theme to favorite...' command * Remove toggle for 'Add current theme to favorite...' command * Added 'Remove current theme from favorite...' command * Merge add/remove commands in a single file * removed dots * updated icon * only showing favorite commands if custom theme is disabled Co-authored-by: Miodec --- frontend/src/ts/commandline/commands.ts | 2 ++ .../lists/add-or-remove-theme-to-favorites.ts | 34 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 frontend/src/ts/commandline/lists/add-or-remove-theme-to-favorites.ts diff --git a/frontend/src/ts/commandline/commands.ts b/frontend/src/ts/commandline/commands.ts index f2a46f373..b13417500 100644 --- a/frontend/src/ts/commandline/commands.ts +++ b/frontend/src/ts/commandline/commands.ts @@ -65,6 +65,7 @@ import ResultSavingCommands from "./lists/result-saving"; import NavigationCommands from "./lists/navigation"; import FontSizeCommands from "./lists/font-size"; import ResultScreenCommands from "./lists/result-screen"; +import AddOrRemoveThemeToFavorite from "./lists/add-or-remove-theme-to-favorites"; import TagsCommands from "./lists/tags"; import CustomThemesListCommands from "./lists/custom-themes-list"; @@ -248,6 +249,7 @@ export const commands: MonkeyTypes.CommandsSubgroup = { ...CustomThemesListCommands, ...FlipTestColorsCommands, ...ColorfulModeCommands, + ...AddOrRemoveThemeToFavorite, { id: "changeCustomBackground", display: "Custom background...", diff --git a/frontend/src/ts/commandline/lists/add-or-remove-theme-to-favorites.ts b/frontend/src/ts/commandline/lists/add-or-remove-theme-to-favorites.ts new file mode 100644 index 000000000..d33f83cb4 --- /dev/null +++ b/frontend/src/ts/commandline/lists/add-or-remove-theme-to-favorites.ts @@ -0,0 +1,34 @@ +import Config, * as UpdateConfig from "../../config"; + +const commands: MonkeyTypes.Command[] = [ + { + id: "addThemeToFavorite", + display: "Add current theme to favorite", + icon: "fa-heart", + available: (): boolean => { + return !Config.customTheme && !Config.favThemes.includes(Config.theme); + }, + exec: (): void => { + const { theme, favThemes, customTheme } = Config; + if (!customTheme && !favThemes.includes(theme)) { + UpdateConfig.setFavThemes([...favThemes, theme]); + } + }, + }, + { + id: "removeThemeFromFavorite", + display: "Remove current theme from favorite", + icon: "fa-heart-broken", + available: (): boolean => { + return !Config.customTheme && Config.favThemes.includes(Config.theme); + }, + exec: (): void => { + const { theme, favThemes, customTheme } = Config; + if (!customTheme && favThemes.includes(theme)) { + UpdateConfig.setFavThemes([...favThemes.filter((t) => t !== theme)]); + } + }, + }, +]; + +export default commands;