import { useCommandsContext } from 'hooks/useCommandsContext' import { CommandArgument } from 'lib/commandTypes' import { useEffect, useRef } from 'react' import { useHotkeys } from 'react-hotkeys-hook' function CommandBarBasicInput({ arg, stepBack, onSubmit, }: { arg: CommandArgument & { inputType: 'string' name: string } stepBack: () => void onSubmit: (event: unknown) => void }) { const { commandBarSend, commandBarState } = useCommandsContext() useHotkeys('mod + k, mod + /', () => commandBarSend({ type: 'Close' })) const inputRef = useRef(null) useEffect(() => { if (inputRef.current) { inputRef.current.focus() inputRef.current.select() } }, [arg, inputRef]) function handleSubmit(e: React.FormEvent) { e.preventDefault() onSubmit(inputRef.current?.value) } return (
) } export default CommandBarBasicInput