diff --git a/src/renderer/components/hotbar/hotbar-switch-command.tsx b/src/renderer/components/hotbar/hotbar-switch-command.tsx index 5e58461268..f8e0f2a04f 100644 --- a/src/renderer/components/hotbar/hotbar-switch-command.tsx +++ b/src/renderer/components/hotbar/hotbar-switch-command.tsx @@ -25,21 +25,35 @@ interface Dependencies { commandOverlay: CommandOverlay; } -function ignoreIf(check: boolean, menuItems: T) { +function ignoreIf(check: boolean, menuItems: T[]): T[] { return check ? [] : menuItems; } -function getHotbarSwitchOptions(hotbars: Hotbar[]): (Hotbar | typeof hotbarAddAction | typeof hotbarRemoveAction | typeof hotbarRenameAction)[] { +interface HotbarSwitchActionOption { + action: typeof hotbarAddAction | typeof hotbarRemoveAction | typeof hotbarRenameAction; +} + +interface SwitchToHotbarOption { + hotbar: Hotbar; +} + +type HotbarSwitchOption = SwitchToHotbarOption | HotbarSwitchActionOption; + +function getHotbarSwitchOptions(hotbars: Hotbar[]): HotbarSwitchOption[] { return [ - ...hotbars, - hotbarAddAction, + ...hotbars.map(hotbar => ({ hotbar })), + { action: hotbarAddAction }, ...ignoreIf(hotbars.length > 1, [ - hotbarRemoveAction, - ] as const), - hotbarRenameAction, + { action: hotbarRemoveAction } as const, + ]), + { action: hotbarRenameAction }, ]; } +function isActionOption(option: HotbarSwitchOption): option is HotbarSwitchActionOption { + return Boolean((option as HotbarSwitchActionOption).action); +} + const NonInjectedHotbarSwitchCommand = observer(({ hotbarStore, commandOverlay, @@ -47,40 +61,45 @@ const NonInjectedHotbarSwitchCommand = observer(({