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 43c33ba5a..3fee0d0c9 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 @@ -1063,8 +1063,6 @@ export default function NewChatPage() { header={ } /> diff --git a/surfsense_web/components/layout/ui/header/Header.tsx b/surfsense_web/components/layout/ui/header/Header.tsx index 0a1bd225e..4f17aa303 100644 --- a/surfsense_web/components/layout/ui/header/Header.tsx +++ b/surfsense_web/components/layout/ui/header/Header.tsx @@ -1,6 +1,11 @@ "use client"; +import { useQuery } from "@tanstack/react-query"; +import { useParams, usePathname } from "next/navigation"; import { NotificationButton } from "@/components/notifications/NotificationButton"; +import { ChatShareButton } from "@/components/new-chat/chat-share-button"; +import { getThreadFull } from "@/lib/chat/thread-persistence"; +import type { ChatVisibility } from "@/lib/chat/thread-persistence"; interface HeaderProps { breadcrumb?: React.ReactNode; @@ -11,6 +16,29 @@ export function Header({ breadcrumb, mobileMenuTrigger, }: HeaderProps) { + const params = useParams(); + const pathname = usePathname(); + + // Check if we're on a chat page + const isChatPage = pathname?.includes("/new-chat") ?? false; + + // Get chat_id from URL params + const chatId = params?.chat_id + ? Number(Array.isArray(params.chat_id) ? params.chat_id[0] : params.chat_id) + : null; + + // Fetch current thread if on chat page and chat_id exists + const { data: currentThread } = useQuery({ + queryKey: ["thread", chatId], + queryFn: () => getThreadFull(chatId!), + enabled: isChatPage && chatId !== null && chatId > 0, + }); + + const handleVisibilityChange = (visibility: ChatVisibility) => { + // Visibility change is handled by ChatShareButton internally + // This callback can be used for additional side effects if needed + }; + return (
{/* Left side - Mobile menu trigger + Breadcrumb */} @@ -23,6 +51,13 @@ export function Header({
{/* Notifications */} + {/* Share button - only show on chat pages when thread exists */} + {isChatPage && currentThread && ( + + )}
); diff --git a/surfsense_web/components/new-chat/chat-header.tsx b/surfsense_web/components/new-chat/chat-header.tsx index fc01b6dd6..a6cf8df3a 100644 --- a/surfsense_web/components/new-chat/chat-header.tsx +++ b/surfsense_web/components/new-chat/chat-header.tsx @@ -5,18 +5,14 @@ import type { GlobalNewLLMConfig, NewLLMConfigPublic, } from "@/contracts/types/new-llm-config.types"; -import type { ChatVisibility, ThreadRecord } from "@/lib/chat/thread-persistence"; -import { ChatShareButton } from "./chat-share-button"; import { ModelConfigSidebar } from "./model-config-sidebar"; import { ModelSelector } from "./model-selector"; interface ChatHeaderProps { searchSpaceId: number; - thread?: ThreadRecord | null; - onThreadVisibilityChange?: (visibility: ChatVisibility) => void; } -export function ChatHeader({ searchSpaceId, thread, onThreadVisibilityChange }: ChatHeaderProps) { +export function ChatHeader({ searchSpaceId }: ChatHeaderProps) { const [sidebarOpen, setSidebarOpen] = useState(false); const [selectedConfig, setSelectedConfig] = useState< NewLLMConfigPublic | GlobalNewLLMConfig | null @@ -52,7 +48,6 @@ export function ChatHeader({ searchSpaceId, thread, onThreadVisibilityChange }: return (
-