Spaces:
Running
Running
Commit ·
8be02a3
1
Parent(s): b65a841
commit 02112
Browse files- src/components/ChatInput.jsx +11 -5
src/components/ChatInput.jsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
import { useState } from "react";
|
| 2 |
|
| 3 |
export default function ChatInput({ onSend, fileUploaded }) {
|
| 4 |
const [input, setInput] = useState("");
|
|
@@ -9,17 +9,23 @@ export default function ChatInput({ onSend, fileUploaded }) {
|
|
| 9 |
setInput("");
|
| 10 |
};
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return (
|
| 14 |
<div className="chat-input">
|
| 15 |
<input
|
| 16 |
placeholder="Paste error, ask DevMate..."
|
| 17 |
value={input}
|
| 18 |
onChange={(e) => setInput(e.target.value)}
|
| 19 |
-
disabled={
|
| 20 |
-
onKeyDown={(e) => e.key === "Enter" &&
|
| 21 |
/>
|
| 22 |
-
<button onClick={handleSubmit} disabled={!
|
| 23 |
</div>
|
| 24 |
);
|
| 25 |
}
|
|
|
|
| 1 |
+
import { useEffect,useState } from "react";
|
| 2 |
|
| 3 |
export default function ChatInput({ onSend, fileUploaded }) {
|
| 4 |
const [input, setInput] = useState("");
|
|
|
|
| 9 |
setInput("");
|
| 10 |
};
|
| 11 |
|
| 12 |
+
useEffect(() => {
|
| 13 |
+
if (!fileUploaded) setInput("");
|
| 14 |
+
}, [fileUploaded]);
|
| 15 |
+
|
| 16 |
+
// Disable input if no file uploaded
|
| 17 |
+
const isInputDisabled = !fileUploaded;
|
| 18 |
+
const isButtonDisabled = !fileUploaded || !input.trim();
|
| 19 |
return (
|
| 20 |
<div className="chat-input">
|
| 21 |
<input
|
| 22 |
placeholder="Paste error, ask DevMate..."
|
| 23 |
value={input}
|
| 24 |
onChange={(e) => setInput(e.target.value)}
|
| 25 |
+
disabled={isInputDisabled} // disable typing if no file
|
| 26 |
+
onKeyDown={(e) => e.key === "Enter" && !isButtonDisabled && handleSubmit()}
|
| 27 |
/>
|
| 28 |
+
<button onClick={handleSubmit} disabled={!isButtonDisabled}>Send</button>
|
| 29 |
</div>
|
| 30 |
);
|
| 31 |
}
|