From 172b0b000c50885e750dc39fd9d7318487d5a072 Mon Sep 17 00:00:00 2001 From: Aditya Sharma Date: Tue, 24 Dec 2024 17:43:59 +0530 Subject: [PATCH] Disable Enter key until input contains text --- .env | 2 +- src/components/side-panel/SidePanel.tsx | 43 +++++++++++++------------ 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/.env b/.env index c1ffb2c11..f86005c19 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ # create your own API KEY at https://aistudio.google.com/apikey -#REACT_APP_GEMINI_API_KEY='' +# REACT_APP_GEMINI_API_KEY='' diff --git a/src/components/side-panel/SidePanel.tsx b/src/components/side-panel/SidePanel.tsx index 2026cc9ab..72b4c30c7 100644 --- a/src/components/side-panel/SidePanel.tsx +++ b/src/components/side-panel/SidePanel.tsx @@ -43,7 +43,7 @@ export default function SidePanel() { } | null>(null); const inputRef = useRef(null); - //scroll the log to the bottom when new logs come in + // Scroll the log to the bottom when new logs come in useEffect(() => { if (loggerRef.current) { const el = loggerRef.current; @@ -55,7 +55,7 @@ export default function SidePanel() { } }, [logs]); - // listen for log events and store them + // Listen for log events and store them useEffect(() => { client.on("log", log); return () => { @@ -64,11 +64,20 @@ export default function SidePanel() { }, [client, log]); const handleSubmit = () => { - client.send([{ text: textInput }]); + if (textInput.trim()) { + client.send([{ text: textInput }]); + setTextInput(""); + if (inputRef.current) { + inputRef.current.value = ""; // Reset the text area + } + } + }; - setTextInput(""); - if (inputRef.current) { - inputRef.current.innerText = ""; + const handleKeyDown = (e: React.KeyboardEvent) => { + if (e.key === "Enter" && !e.shiftKey && textInput.trim()) { + e.preventDefault(); + e.stopPropagation(); + handleSubmit(); } }; @@ -104,8 +113,8 @@ export default function SidePanel() { backgroundColor: isFocused ? "var(--Neutral-30)" : isSelected - ? "var(--Neutral-20)" - : undefined, + ? "var(--Neutral-20)" + : undefined, }), }} defaultValue={selectedOption} @@ -121,36 +130,28 @@ export default function SidePanel() {
- +
- Type something... - + >