import classNames from "classnames"; import { useRef, useState } from "react"; import { HiLightBulb, HiSearch } from "react-icons/hi"; import { useUpdateEffect } from "react-use"; import { useInputGeneration } from "./main/hooks/useInputGeneration"; export const InputGeneration: React.FC = () => { const { prompt, setPrompt, submit, loading } = useInputGeneration(); const [value, setValue] = useState(prompt); const input = useRef(null); useUpdateEffect(() => setValue(prompt), [prompt]); return (
input.current?.focus()} >
setValue(e.target.value)} onBlur={() => setPrompt(value)} onKeyDown={(e) => { if (e.key === "Enter" && (value || prompt) && !loading) { setPrompt(value); setTimeout(() => { submit(); }, 10); } }} />
); };