diff --git a/autogpt_platform/frontend/CONTRIBUTING.md b/autogpt_platform/frontend/CONTRIBUTING.md index 7bda2ad02a..649bb1ca92 100644 --- a/autogpt_platform/frontend/CONTRIBUTING.md +++ b/autogpt_platform/frontend/CONTRIBUTING.md @@ -175,6 +175,8 @@ While server components and actions are cool and cutting-edge, they introduce a - Prefer [React Query](https://tanstack.com/query/latest/docs/framework/react/overview) for server state, colocated near consumers (see [state colocation](https://kentcdodds.com/blog/state-colocation-will-make-your-react-app-faster)) - Co-locate UI state inside components/hooks; keep global state minimal +- Avoid `useMemo` and `useCallback` unless you have a measured performance issue +- Do not abuse `useEffect`; prefer state colocation and derive values directly when possible ### Styling and components diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/chat/useCopilotChatPage.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/chat/useCopilotChatPage.ts index eb86185bb0..e6416d9037 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot/chat/useCopilotChatPage.ts +++ b/autogpt_platform/frontend/src/app/(platform)/copilot/chat/useCopilotChatPage.ts @@ -8,7 +8,7 @@ import { } from "@/services/feature-flags/use-get-flag"; import { useFlags } from "launchdarkly-react-client-sdk"; import { useRouter, useSearchParams } from "next/navigation"; -import { useEffect } from "react"; +import { useEffect, useState } from "react"; export function useCopilotChatPage() { const router = useRouter(); @@ -24,6 +24,22 @@ export function useCopilotChatPage() { const sessionId = searchParams.get("sessionId"); const prompt = searchParams.get("prompt"); + const [storedPrompt, setStoredPrompt] = useState(null); + + useEffect( + function loadStoredPrompt() { + if (prompt) return; + try { + const storedValue = sessionStorage.getItem("copilot_initial_prompt"); + if (!storedValue) return; + sessionStorage.removeItem("copilot_initial_prompt"); + setStoredPrompt(storedValue); + } catch { + // Ignore storage errors (private mode, etc.) + } + }, + [prompt], + ); useEffect( function guardAccess() { @@ -39,6 +55,6 @@ export function useCopilotChatPage() { isFlagReady, isChatEnabled, sessionId, - prompt, + prompt: prompt ?? storedPrompt, }; } diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/CopilotShell.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/CopilotShell.tsx index 54865a7db6..fa19ab88a7 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/CopilotShell.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/CopilotShell.tsx @@ -19,6 +19,7 @@ export function CopilotShell({ children }: Props) { isDrawerOpen, isLoading, isLoggedIn, + hasActiveSession, sessions, currentSessionId, handleSelectSession, @@ -38,7 +39,7 @@ export function CopilotShell({ children }: Props) { return (
{!isMobile && ( @@ -51,10 +52,11 @@ export function CopilotShell({ children }: Props) { onSelectSession={handleSelectSession} onFetchNextPage={fetchNextPage} onNewChat={handleNewChat} + hasActiveSession={Boolean(hasActiveSession)} /> )} -
+
{isMobile && }
{isReadyToShowContent ? children : } @@ -74,6 +76,7 @@ export function CopilotShell({ children }: Props) { onNewChat={handleNewChat} onClose={handleCloseDrawer} onOpenChange={handleDrawerOpenChange} + hasActiveSession={Boolean(hasActiveSession)} /> )}
diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/components/DesktopSidebar/DesktopSidebar.tsx b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/components/DesktopSidebar/DesktopSidebar.tsx index d1abd2cfb0..122a09a02f 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/components/DesktopSidebar/DesktopSidebar.tsx +++ b/autogpt_platform/frontend/src/app/(platform)/copilot/components/CopilotShell/components/DesktopSidebar/DesktopSidebar.tsx @@ -15,6 +15,7 @@ interface Props { onSelectSession: (sessionId: string) => void; onFetchNextPage: () => void; onNewChat: () => void; + hasActiveSession: boolean; } export function DesktopSidebar({ @@ -26,9 +27,10 @@ export function DesktopSidebar({ onSelectSession, onFetchNextPage, onNewChat, + hasActiveSession, }: Props) { return ( -