From e928a8eee42ccddf18040dc204c658768d7b06a6 Mon Sep 17 00:00:00 2001 From: Mike Averto <603286+mjaverto@users.noreply.github.com> Date: Fri, 21 Mar 2025 12:00:18 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=BC=20feat:=20Add=20Auto=20Submit=20Fo?= =?UTF-8?q?r=20URL=20Query=20Params=20(#6440)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add submit query param to auto submit a prompt passed in via URL * refactor: add case-insensitive value for auto-submit --------- Co-authored-by: Danny Avila --- client/src/hooks/Input/useQueryParams.ts | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/client/src/hooks/Input/useQueryParams.ts b/client/src/hooks/Input/useQueryParams.ts index 072a5b74e9..94c036500d 100644 --- a/client/src/hooks/Input/useQueryParams.ts +++ b/client/src/hooks/Input/useQueryParams.ts @@ -14,6 +14,7 @@ import type { ZodAny } from 'zod'; import { getConvoSwitchLogic, removeUnavailableTools } from '~/utils'; import useDefaultConvo from '~/hooks/Conversations/useDefaultConvo'; import { useChatContext, useChatFormContext } from '~/Providers'; +import useSubmitMessage from '~/hooks/Messages/useSubmitMessage'; import store from '~/store'; const parseQueryValue = (value: string) => { @@ -76,6 +77,7 @@ export default function useQueryParams({ const getDefaultConversation = useDefaultConvo(); const modularChat = useRecoilValue(store.modularChat); const availableTools = useRecoilValue(store.availableTools); + const { submitMessage } = useSubmitMessage(); const queryClient = useQueryClient(); const { conversation, newConversation } = useChatContext(); @@ -160,10 +162,12 @@ export default function useQueryParams({ }); const decodedPrompt = queryParams.prompt || ''; + const shouldAutoSubmit = queryParams.submit?.toLowerCase() === 'true'; delete queryParams.prompt; + delete queryParams.submit; const validSettings = processValidSettings(queryParams); - return { decodedPrompt, validSettings }; + return { decodedPrompt, validSettings, shouldAutoSubmit }; }; const intervalId = setInterval(() => { @@ -180,7 +184,7 @@ export default function useQueryParams({ if (!textAreaRef.current) { return; } - const { decodedPrompt, validSettings } = processQueryParams(); + const { decodedPrompt, validSettings, shouldAutoSubmit } = processQueryParams(); const currentText = methods.getValues('text'); /** Clean up URL parameters after successful processing */ @@ -196,6 +200,15 @@ export default function useQueryParams({ methods.setValue('text', decodedPrompt, { shouldValidate: true }); textAreaRef.current.focus(); textAreaRef.current.setSelectionRange(decodedPrompt.length, decodedPrompt.length); + + // Auto-submit if the submit parameter is true + if (shouldAutoSubmit) { + methods.handleSubmit((data) => { + if (data.text?.trim()) { + submitMessage(data); + } + })(); + } } if (Object.keys(validSettings).length > 0) { @@ -208,5 +221,5 @@ export default function useQueryParams({ return () => { clearInterval(intervalId); }; - }, [searchParams, methods, textAreaRef, newQueryConvo, newConversation]); + }, [searchParams, methods, textAreaRef, newQueryConvo, newConversation, submitMessage]); }