From f915e66f74633088e3e8f9cb93b7b55a6515ada7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20Su=C3=A1rez?= <59179297+stevecode21@users.noreply.github.com> Date: Tue, 10 Sep 2024 10:58:13 -0500 Subject: [PATCH] Implementing query search --- ui/components/EmptyChatMessageInput.tsx | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ui/components/EmptyChatMessageInput.tsx b/ui/components/EmptyChatMessageInput.tsx index 39d3f16..f509d3d 100644 --- a/ui/components/EmptyChatMessageInput.tsx +++ b/ui/components/EmptyChatMessageInput.tsx @@ -18,6 +18,12 @@ const EmptyChatMessageInput = ({ const inputRef = useRef(null); + // Function to extract query parameter from URL + const getQueryFromURL = () => { + const urlParams = new URLSearchParams(window.location.search); + return urlParams.get('query') || ''; + }; + useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { const activeElement = document.activeElement; @@ -33,12 +39,19 @@ const EmptyChatMessageInput = ({ } }; + // Handle query parameter on initial load + const initialQuery = getQueryFromURL(); + if (initialQuery) { + setMessage(initialQuery); // Set the query to the message input + sendMessage(initialQuery); // Automatically send the message + } + document.addEventListener('keydown', handleKeyDown); return () => { document.removeEventListener('keydown', handleKeyDown); }; - }, []); + }, [sendMessage]); return (
- {/* */}