From 821e508da3c3e1ac8a51d344fb78e7755db6deda Mon Sep 17 00:00:00 2001 From: Jesse Bofill Date: Mon, 8 Jan 2024 15:52:52 -0700 Subject: [PATCH] chore: simplify tab profiles menu --- .../context-menus/TabProfileMenu.tsx | 66 +++++++++---------- 1 file changed, 30 insertions(+), 36 deletions(-) diff --git a/src/components/context-menus/TabProfileMenu.tsx b/src/components/context-menus/TabProfileMenu.tsx index 212b7ce..2afbdc8 100644 --- a/src/components/context-menus/TabProfileMenu.tsx +++ b/src/components/context-menus/TabProfileMenu.tsx @@ -1,7 +1,10 @@ -import { Menu, MenuGroup, MenuItem, showModal } from 'decky-frontend-lib'; -import { VFC, Fragment } from 'react'; +import { Menu, MenuGroup, MenuItem, showModal, GamepadButton, ConfirmModal } from 'decky-frontend-lib'; +import { VFC, Fragment, useState } from 'react'; import { TabMasterManager } from '../../state/TabMasterManager'; import { CreateTabProfileModal, OverwriteTabProfileModal } from '../modals/TabProfileModals'; +import { gamepadContextMenuClasses } from '../../lib/GamepadContextMenuClasses'; +import { DestructiveModal } from '../generic/DestructiveModal'; + interface TabsProfilesMenuProps { tabMasterManager: TabMasterManager, @@ -29,49 +32,40 @@ export const TabProfilesSubMenu: VFC = ({ tabMasterManage * Menu items for the Tab Profiles context menu. */ const TabProfileMenuItems: VFC = ({ tabMasterManager }) => { + const [_refresh, setRefresh] = useState(true); return ( <> showModal()}> Create Profile - - {/*
*/} - - - ); -}; - -/** - * The overwrite menu for Tab Profiles. - */ -const OverwriteTabProfileMenu: VFC = ({ tabMasterManager }) => { - return ( - - {Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => { +
+ {Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(profileName => { return ( - showModal()}> - {snapshotName} + tabMasterManager.tabProfileManager?.apply(profileName, tabMasterManager)} + actionDescriptionMap={{ + [GamepadButton.OK]: 'Apply Profile', + [GamepadButton.SECONDARY]: 'Delete Profile', //X + [GamepadButton.OPTIONS]: 'Overwrite Profile', //Y + }} + onSecondaryButton={() => + showModal( { + tabMasterManager.tabProfileManager?.delete(profileName); + setRefresh(cur => !cur); + }} + strTitle={`Deleting Profile: ${profileName}`} + > + Are you sure you want to delete this profile? + ) + } + onOptionsButton={() => showModal()} + > + {profileName} ); })} - - ); -}; - -/** - * The apply menu for Tab Profiles. - */ -const ApplyTabProfile: VFC = ({ tabMasterManager }) => { - return ( - - {Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => { - return ( - tabMasterManager.tabProfileManager?.apply(snapshotName, tabMasterManager)}> - {snapshotName} - - ); - })} - + ); };