From 41397ee91113a2ba4f660c20e4fc9f6ff15b8e75 Mon Sep 17 00:00:00 2001 From: mbeaulne Date: Tue, 11 Aug 2026 14:56:04 -0400 Subject: [PATCH] Move the new session button to the header so we have it globally --- apps/web/src/routes/layout/AppTopNav.tsx | 2 + .../routes/layout/NewSessionTopNavAction.tsx | 58 +++++++++++++++++++ apps/web/src/routes/sessions/SessionsPage.tsx | 41 ------------- 3 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 apps/web/src/routes/layout/NewSessionTopNavAction.tsx diff --git a/apps/web/src/routes/layout/AppTopNav.tsx b/apps/web/src/routes/layout/AppTopNav.tsx index a4ccb11..16ac51b 100644 --- a/apps/web/src/routes/layout/AppTopNav.tsx +++ b/apps/web/src/routes/layout/AppTopNav.tsx @@ -6,6 +6,7 @@ import { UserAvatar } from "@/features/user/components/UserAvatar"; import { useCurrentUser } from "@/features/user/hooks/useCurrentUser"; import { TopNav, TopNavLink } from "@/shared/ui/patterns/top-nav"; +import { NewSessionTopNavAction } from "./NewSessionTopNavAction"; import { TangleLogo } from "./TangleLogo"; import { ThemeMenu } from "./ThemeMenu"; @@ -38,6 +39,7 @@ export function AppTopNav() { } actions={ <> + diff --git a/apps/web/src/routes/layout/NewSessionTopNavAction.tsx b/apps/web/src/routes/layout/NewSessionTopNavAction.tsx new file mode 100644 index 0000000..10b26fc --- /dev/null +++ b/apps/web/src/routes/layout/NewSessionTopNavAction.tsx @@ -0,0 +1,58 @@ +import type { Session } from "@tangent/shared/contracts"; +import { useNavigate } from "@tanstack/react-router"; + +import { useAgentBundles } from "@/features/agent-bundles/hooks/useAgentBundles"; +import { useCreateSession } from "@/features/sessions/hooks/useCreateSession"; +import { env } from "@/shared/config/env"; + +import { NewSessionButton } from "../sessions/components/NewSessionButton"; + +export function NewSessionTopNavAction() { + const { data: bundles } = useAgentBundles(); + const { + mutate: createSession, + isPending: isCreating, + isError, + error, + } = useCreateSession(); + const navigate = useNavigate(); + const defaultBundle = bundles?.find( + (bundle) => bundle.id === env.defaultSessionBundleId, + ); + const defaultBundleName = defaultBundle?.name ?? env.defaultSessionBundleId; + + const openSession = (session: Session) => + void navigate({ + to: "/sessions/$sessionId", + params: { sessionId: session.id }, + }); + + const startDefaultBundle = () => + createSession( + { bundleId: env.defaultSessionBundleId, name: defaultBundleName }, + { onSuccess: openSession }, + ); + + const startFromBundle = (bundleId: string, name: string) => + createSession({ bundleId, name }, { onSuccess: openSession }); + + return ( + <> + {isError ? ( + + Failed to create session + + ) : null} + + + ); +} diff --git a/apps/web/src/routes/sessions/SessionsPage.tsx b/apps/web/src/routes/sessions/SessionsPage.tsx index 0a2ec6c..11855f1 100644 --- a/apps/web/src/routes/sessions/SessionsPage.tsx +++ b/apps/web/src/routes/sessions/SessionsPage.tsx @@ -5,26 +5,15 @@ import { Paragraph } from "@tangent/ui-primitives/typography"; import { useNavigate } from "@tanstack/react-router"; import { useState } from "react"; -import { useAgentBundles } from "@/features/agent-bundles/hooks/useAgentBundles"; -import { useCreateSession } from "@/features/sessions/hooks/useCreateSession"; import { useSessions } from "@/features/sessions/hooks/useSessions"; -import { env } from "@/shared/config/env"; import { EmptyState } from "@/shared/ui/patterns/empty-state"; import { PageHeader } from "@/shared/ui/patterns/page-header"; import { WorkArea } from "@/shared/ui/patterns/work-area"; -import { NewSessionButton } from "./components/NewSessionButton"; import { SessionsTable } from "./components/SessionsTable"; export function SessionsPage() { const { data: sessions, isLoading, error } = useSessions(); - const { data: bundles } = useAgentBundles(); - const { - mutate: createSession, - isPending: isCreating, - isError: isCreateError, - error: createError, - } = useCreateSession(); const navigate = useNavigate(); const [showArchived, setShowArchived] = useState(false); @@ -32,10 +21,6 @@ export function SessionsPage() { const visibleSessions = showArchived ? sessions : sessions?.filter((session) => !session.archived); - const defaultBundle = bundles?.find( - (bundle) => bundle.id === env.defaultSessionBundleId, - ); - const defaultBundleName = defaultBundle?.name ?? env.defaultSessionBundleId; const openSession = (session: Session) => void navigate({ @@ -43,24 +28,6 @@ export function SessionsPage() { params: { sessionId: session.id }, }); - const startDefaultBundle = () => - createSession( - { bundleId: env.defaultSessionBundleId, name: defaultBundleName }, - { onSuccess: openSession }, - ); - - const startFromBundle = (bundleId: string, name: string) => - createSession({ bundleId, name }, { onSuccess: openSession }); - - const newSessionButton = ( - - ); - return ( @@ -75,12 +42,6 @@ export function SessionsPage() { ) : null} - {isCreateError ? ( - - Failed to create session: {createError.message} - - ) : null} - {isLoading ? ( Loading sessions... @@ -92,7 +53,6 @@ export function SessionsPage() { icon="FolderOpen" title="No sessions yet" description="Start with the default bundle or choose another agent bundle to get started." - action={newSessionButton} /> ) : null} @@ -109,7 +69,6 @@ export function SessionsPage() { sessions={visibleSessions ?? []} onOpen={openSession} /> - {newSessionButton} ) : null}