Skip to content

Commit

Permalink
chore: simplify tab profiles menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jessebofill committed Jan 8, 2024
1 parent 7b9bd33 commit 821e508
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions src/components/context-menus/TabProfileMenu.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -29,49 +32,40 @@ export const TabProfilesSubMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManage
* Menu items for the Tab Profiles context menu.
*/
const TabProfileMenuItems: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
const [_refresh, setRefresh] = useState(true);
return (
<>
<MenuItem onClick={() => showModal(<CreateTabProfileModal tabMasterManager={tabMasterManager} />)}>
Create Profile
</MenuItem>
<OverwriteTabProfileMenu tabMasterManager={tabMasterManager} />
{/* <div className={gamepadContextMenuClasses.ContextMenuSeparator} /> */}
<ApplyTabProfile tabMasterManager={tabMasterManager} />
</>
);
};

/**
* The overwrite menu for Tab Profiles.
*/
const OverwriteTabProfileMenu: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return (
<MenuGroup label='Overwrite Tab Profile' disabled={Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).length === 0}>
{Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => {
<div className={gamepadContextMenuClasses.ContextMenuSeparator} />
{Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(profileName => {
return (
<MenuItem onClick={() => showModal(<OverwriteTabProfileModal profileName={snapshotName} tabMasterManager={tabMasterManager} />)}>
{snapshotName}
<MenuItem
onClick= {() => tabMasterManager.tabProfileManager?.apply(profileName, tabMasterManager)}
actionDescriptionMap={{
[GamepadButton.OK]: 'Apply Profile',
[GamepadButton.SECONDARY]: 'Delete Profile', //X
[GamepadButton.OPTIONS]: 'Overwrite Profile', //Y
}}
onSecondaryButton={() =>
showModal(<DestructiveModal
onOK={() => {
tabMasterManager.tabProfileManager?.delete(profileName);
setRefresh(cur => !cur);
}}
strTitle={`Deleting Profile: ${profileName}`}
>
Are you sure you want to delete this profile?
</DestructiveModal>)
}
onOptionsButton={() => showModal(<OverwriteTabProfileModal profileName={profileName} tabMasterManager={tabMasterManager} />)}
>
{profileName}
</MenuItem>
);
})}
</MenuGroup>
);
};

/**
* The apply menu for Tab Profiles.
*/
const ApplyTabProfile: VFC<TabsProfilesMenuProps> = ({ tabMasterManager }) => {
return (
<MenuGroup label='Apply Tab Profile' disabled={Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).length === 0}>
{Object.keys(tabMasterManager.tabProfileManager?.tabProfiles ?? {}).map(snapshotName => {
return (
<MenuItem onClick={() => tabMasterManager.tabProfileManager?.apply(snapshotName, tabMasterManager)}>
{snapshotName}
</MenuItem>
);
})}
</MenuGroup>
</>
);
};

Expand Down

0 comments on commit 821e508

Please sign in to comment.