diff --git a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx index 5024c446c..b0928d9b2 100644 --- a/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx +++ b/surfsense_web/app/dashboard/[search_space_id]/new-chat/[[...chat_id]]/page.tsx @@ -166,22 +166,16 @@ function QuickAskAutoSubmit() { useEffect(() => { if (!window.electronAPI || handledRef.current) return; + if (sessionStorage.getItem("quickAskAutoSubmit") === "false") return; const prompt = searchParams.get("quickAskPrompt"); - const initialText = searchParams.get("quickAskInitialText"); + if (!prompt) return; - if (prompt) { - handledRef.current = true; - setTimeout(() => { - aui.composer().setText(prompt); - aui.composer().send(); - }, 500); - } else if (initialText) { - handledRef.current = true; - setTimeout(() => { - aui.composer().setText(initialText); - }, 500); - } + handledRef.current = true; + setTimeout(() => { + aui.composer().setText(prompt); + aui.composer().send(); + }, 500); }, [searchParams, aui]); return null; diff --git a/surfsense_web/app/dashboard/quick-ask/page.tsx b/surfsense_web/app/dashboard/quick-ask/page.tsx index 95395c14d..e4fb18dde 100644 --- a/surfsense_web/app/dashboard/quick-ask/page.tsx +++ b/surfsense_web/app/dashboard/quick-ask/page.tsx @@ -37,6 +37,7 @@ export default function QuickAskPage() { const navigateToChat = (prompt: string, mode: string) => { sessionStorage.setItem("quickAskMode", mode); + sessionStorage.setItem("quickAskAutoSubmit", "true"); const encoded = encodeURIComponent(prompt); window.location.href = `/dashboard?quickAskPrompt=${encoded}`; }; @@ -44,8 +45,9 @@ export default function QuickAskPage() { const navigateWithInitialText = () => { if (!clipboardText) return; sessionStorage.setItem("quickAskMode", "explore"); - const encoded = encodeURIComponent(clipboardText); - window.location.href = `/dashboard?quickAskInitialText=${encoded}`; + sessionStorage.setItem("quickAskAutoSubmit", "false"); + sessionStorage.setItem("quickAskInitialText", clipboardText); + window.location.href = `/dashboard?quickAskPrompt=${encodeURIComponent(clipboardText)}`; }; const handleAction = (actionId: string) => { diff --git a/surfsense_web/components/assistant-ui/thread.tsx b/surfsense_web/components/assistant-ui/thread.tsx index 195afc090..059aaf5a0 100644 --- a/surfsense_web/components/assistant-ui/thread.tsx +++ b/surfsense_web/components/assistant-ui/thread.tsx @@ -306,6 +306,18 @@ const Composer: FC = () => { const aui = useAui(); const hasAutoFocusedRef = useRef(false); + const [quickAskInitialText, setQuickAskInitialText] = useState(); + useEffect(() => { + if (!window.electronAPI) return; + if (sessionStorage.getItem("quickAskAutoSubmit") === "false") { + const text = sessionStorage.getItem("quickAskInitialText"); + if (text) { + setQuickAskInitialText(text); + sessionStorage.removeItem("quickAskInitialText"); + } + } + }, []); + const isThreadEmpty = useAuiState(({ thread }) => thread.isEmpty); const isThreadRunning = useAuiState(({ thread }) => thread.isRunning); @@ -512,6 +524,7 @@ const Composer: FC = () => { onDocumentRemove={handleDocumentRemove} onSubmit={handleSubmit} onKeyDown={handleKeyDown} + initialText={quickAskInitialText} className="min-h-[24px]" />