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