import { CommandArgument } from 'lib/commandTypes' import { commandBarActor, useCommandBarState } from 'machines/commandBarMachine' 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 commandBarState = useCommandBarState() useHotkeys('mod + k, mod + /', () => commandBarActor.send({ 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