import { useCommandsContext } from 'hooks/useCommandsContext' import { CustomIcon } from '../CustomIcon' import React, { ReactNode, useState } from 'react' import { ActionButton } from '../ActionButton' import { Selections, getSelectionTypeDisplayText } from 'lib/selections' import { useHotkeys } from 'react-hotkeys-hook' function CommandBarHeader({ children }: React.PropsWithChildren<{}>) { const { commandBarState, commandBarSend } = useCommandsContext() const { context: { selectedCommand, currentArgument, argumentsToSubmit }, } = commandBarState const isReviewing = commandBarState.matches('Review') const [showShortcuts, setShowShortcuts] = useState(false) useHotkeys( 'alt', () => setShowShortcuts(true), { enableOnFormTags: true, enableOnContentEditable: true }, [showShortcuts] ) useHotkeys( 'alt', () => setShowShortcuts(false), { keyup: true, enableOnFormTags: true, enableOnContentEditable: true }, [showShortcuts] ) useHotkeys( [ 'alt+1', 'alt+2', 'alt+3', 'alt+4', 'alt+5', 'alt+6', 'alt+7', 'alt+8', 'alt+9', 'alt+0', ], (_, b) => { if (b.keys && !Number.isNaN(parseInt(b.keys[0], 10))) { if (!selectedCommand?.args) return const argName = Object.keys(selectedCommand.args)[ parseInt(b.keys[0], 10) - 1 ] const arg = selectedCommand?.args[argName] commandBarSend({ type: 'Change current argument', data: { arg: { ...arg, name: argName } }, }) } }, { keyup: true, enableOnFormTags: true, enableOnContentEditable: true }, [argumentsToSubmit, selectedCommand] ) return ( selectedCommand && argumentsToSubmit && ( <>
{selectedCommand &&
'icon' in selectedCommand &&
selectedCommand.icon && (