From 325a666a8b0e6f4d3cf4b42cebfbb86dc8544846 Mon Sep 17 00:00:00 2001 From: Waleed Date: Wed, 17 Sep 2025 12:28:22 -0700 Subject: [PATCH] improvement(landing): insert prompt into copilot panel from landing, open panel on entry (#1363) * update infra and remove railway * improvement(landing): insert prompt into copilot panel from landing, open panel on entry * Revert "update infra and remove railway" This reverts commit abfa2f8d51901247acc6397960210569e84d72b1. * fixes * remove debug logs * go back to old env --- .../app/(landing)/components/hero/hero.tsx | 2 + .../copilot/components/welcome/welcome.tsx | 3 +- .../panel/components/copilot/copilot.tsx | 14 +- .../w/[workflowId]/components/panel/panel.tsx | 37 +++- apps/sim/lib/browser-storage.ts | 189 ++++++++++++++++++ apps/sim/stores/panel/store.ts | 4 + apps/sim/stores/panel/types.ts | 1 + 7 files changed, 241 insertions(+), 9 deletions(-) create mode 100644 apps/sim/lib/browser-storage.ts diff --git a/apps/sim/app/(landing)/components/hero/hero.tsx b/apps/sim/app/(landing)/components/hero/hero.tsx index 154edbe7fa..7169925df1 100644 --- a/apps/sim/app/(landing)/components/hero/hero.tsx +++ b/apps/sim/app/(landing)/components/hero/hero.tsx @@ -32,6 +32,7 @@ import { StripeIcon, SupabaseIcon, } from '@/components/icons' +import { LandingPromptStorage } from '@/lib/browser-storage' import { soehne } from '@/app/fonts/soehne/soehne' import { CARD_WIDTH, @@ -271,6 +272,7 @@ export default function Hero() { */ const handleSubmit = () => { if (!isEmpty) { + LandingPromptStorage.store(textValue) router.push('/signup') } } diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/welcome/welcome.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/welcome/welcome.tsx index 79415b13ad..84aafbbd03 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/welcome/welcome.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/components/welcome/welcome.tsx @@ -1,6 +1,6 @@ 'use client' -import { Blocks, Bot, LibraryBig, Workflow } from 'lucide-react' +import { Blocks, LibraryBig, Workflow } from 'lucide-react' interface CopilotWelcomeProps { onQuestionClick?: (question: string) => void @@ -59,7 +59,6 @@ export function CopilotWelcome({ onQuestionClick, mode = 'ask' }: CopilotWelcome
{/* Header */}
-

{subtitle}

diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx index 8bfa7a0e6e..1665032e7a 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/components/copilot/copilot.tsx @@ -30,6 +30,7 @@ interface CopilotProps { interface CopilotRef { createNewChat: () => void + setInputValueAndFocus: (value: string) => void } export const Copilot = forwardRef(({ panelWidth }, ref) => { @@ -326,13 +327,24 @@ export const Copilot = forwardRef(({ panelWidth }, ref }, 100) // Small delay to ensure DOM updates are complete }, [createNewChat]) + const handleSetInputValueAndFocus = useCallback( + (value: string) => { + setInputValue(value) + setTimeout(() => { + userInputRef.current?.focus() + }, 150) + }, + [setInputValue] + ) + // Expose functions to parent useImperativeHandle( ref, () => ({ createNewChat: handleStartNewChat, + setInputValueAndFocus: handleSetInputValueAndFocus, }), - [handleStartNewChat] + [handleStartNewChat, handleSetInputValueAndFocus] ) // Handle abort action diff --git a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx index 6c26be1b9b..e0d2a7a51c 100644 --- a/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx +++ b/apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/panel/panel.tsx @@ -9,6 +9,7 @@ import { } from '@/components/ui/dropdown-menu' import { ScrollArea } from '@/components/ui/scroll-area' import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip' +import { LandingPromptStorage } from '@/lib/browser-storage' import { createLogger } from '@/lib/logs/console/logger' import { useCopilotStore } from '@/stores/copilot/store' import { useChatStore } from '@/stores/panel/chat/store' @@ -31,6 +32,7 @@ export function Panel() { const [resizeStartWidth, setResizeStartWidth] = useState(0) const copilotRef = useRef<{ createNewChat: () => void + setInputValueAndFocus: (value: string) => void }>(null) const lastLoadedWorkflowRef = useRef(null) @@ -289,17 +291,40 @@ export function Panel() { } }, [activeWorkflowId, copilotWorkflowId, ensureCopilotDataLoaded]) + useEffect(() => { + const storedPrompt = LandingPromptStorage.consume() + + if (storedPrompt && storedPrompt.trim().length > 0) { + setActiveTab('copilot') + if (!isOpen) { + togglePanel() + } + + setTimeout(() => { + if (copilotRef.current) { + copilotRef.current.setInputValueAndFocus(storedPrompt) + } else { + setTimeout(() => { + if (copilotRef.current) { + copilotRef.current.setInputValueAndFocus(storedPrompt) + } + }, 500) + } + }, 200) + } + }, []) // eslint-disable-line react-hooks/exhaustive-deps -- Run only on mount + return ( <> {/* Tab Selector - Always visible */}