DevMate / src /components /ChatInput.jsx
FrederickSundeep's picture
commit 021151
5aa6c68
raw
history blame
927 Bytes
import { useEffect,useState } from "react";
export default function ChatInput({ onSend, fileUploaded }) {
const [input, setInput] = useState("");
const handleSubmit = () => {
if (!input.trim() || !fileUploaded) return;
onSend(input);
setInput("");
};
useEffect(() => {
if (!fileUploaded) setInput("");
}, [fileUploaded]);
// Disable input if no file uploaded
const isInputDisabled = !fileUploaded;
const isButtonDisabled = !fileUploaded || !input.trim();
return (
<div className="chat-input">
<input
placeholder="Paste error, ask DevMate..."
value={input}
onChange={(e) => setInput(e.target.value)}
disabled={isInputDisabled} // disable typing if no file
onKeyDown={(e) => e.key === "Enter" && !isButtonDisabled && handleSubmit()}
/>
<button onClick={handleSubmit} disabled={!isButtonDisabled}>Send</button>
</div>
);
}