2026-01-08 19:10:40 +02:00
|
|
|
"use client";
|
|
|
|
|
|
2026-03-29 21:27:10 +05:30
|
|
|
import { useAtomValue } from "jotai";
|
2026-01-20 16:33:42 +05:30
|
|
|
import { usePathname } from "next/navigation";
|
|
|
|
|
import { currentThreadAtom } from "@/atoms/chat/current-thread.atom";
|
2026-03-06 22:38:49 +05:30
|
|
|
import { activeSearchSpaceIdAtom } from "@/atoms/search-spaces/search-space-query.atoms";
|
2026-03-29 21:27:10 +05:30
|
|
|
import { activeTabAtom, tabsAtom } from "@/atoms/tabs/tabs.atom";
|
2026-03-06 22:38:49 +05:30
|
|
|
import { ChatHeader } from "@/components/new-chat/chat-header";
|
2026-01-20 16:14:57 +05:30
|
|
|
import { ChatShareButton } from "@/components/new-chat/chat-share-button";
|
2026-03-11 01:22:24 +05:30
|
|
|
import { useIsMobile } from "@/hooks/use-mobile";
|
2026-01-20 16:33:42 +05:30
|
|
|
import type { ChatVisibility, ThreadRecord } from "@/lib/chat/thread-persistence";
|
2026-03-31 21:29:46 -07:00
|
|
|
import { RightPanelExpandButton } from "../right-panel/RightPanel";
|
2026-01-08 19:10:40 +02:00
|
|
|
|
|
|
|
|
interface HeaderProps {
|
|
|
|
|
mobileMenuTrigger?: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 22:33:42 +05:30
|
|
|
export function Header({ mobileMenuTrigger }: HeaderProps) {
|
2026-01-20 16:14:57 +05:30
|
|
|
const pathname = usePathname();
|
2026-03-06 22:38:49 +05:30
|
|
|
const searchSpaceId = useAtomValue(activeSearchSpaceIdAtom);
|
2026-03-11 01:22:24 +05:30
|
|
|
const isMobile = useIsMobile();
|
2026-03-27 01:39:15 -07:00
|
|
|
const activeTab = useAtomValue(activeTabAtom);
|
2026-03-29 21:27:10 +05:30
|
|
|
const tabs = useAtomValue(tabsAtom);
|
2026-01-20 20:47:31 +05:30
|
|
|
|
2026-01-20 16:14:57 +05:30
|
|
|
const isChatPage = pathname?.includes("/new-chat") ?? false;
|
2026-03-27 01:39:15 -07:00
|
|
|
const isDocumentTab = activeTab?.type === "document";
|
2026-03-29 21:27:10 +05:30
|
|
|
const hasTabBar = tabs.length > 1;
|
2026-01-20 20:47:31 +05:30
|
|
|
|
2026-01-20 16:33:42 +05:30
|
|
|
const currentThreadState = useAtomValue(currentThreadAtom);
|
2026-01-20 20:47:31 +05:30
|
|
|
|
2026-03-27 01:39:15 -07:00
|
|
|
const hasThread = isChatPage && !isDocumentTab && currentThreadState.id !== null;
|
2026-01-20 20:47:31 +05:30
|
|
|
|
2026-01-20 16:35:49 +05:30
|
|
|
const threadForButton: ThreadRecord | null =
|
|
|
|
|
hasThread && currentThreadState.id !== null
|
|
|
|
|
? {
|
|
|
|
|
id: currentThreadState.id,
|
|
|
|
|
visibility: currentThreadState.visibility ?? "PRIVATE",
|
|
|
|
|
created_by_id: null,
|
|
|
|
|
search_space_id: 0,
|
|
|
|
|
title: "",
|
|
|
|
|
archived: false,
|
|
|
|
|
created_at: "",
|
|
|
|
|
updated_at: "",
|
|
|
|
|
}
|
|
|
|
|
: null;
|
2026-01-20 16:14:57 +05:30
|
|
|
|
2026-03-06 22:38:49 +05:30
|
|
|
const handleVisibilityChange = (_visibility: ChatVisibility) => {};
|
2026-01-20 16:14:57 +05:30
|
|
|
|
2026-01-08 19:10:40 +02:00
|
|
|
return (
|
2026-03-31 16:35:29 +05:30
|
|
|
<header className="sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 bg-main-panel/95 backdrop-blur supports-backdrop-filter:bg-main-panel/60 px-4">
|
2026-03-06 22:38:49 +05:30
|
|
|
{/* Left side - Mobile menu trigger + Model selector */}
|
2026-01-08 19:10:40 +02:00
|
|
|
<div className="flex flex-1 items-center gap-2 min-w-0">
|
|
|
|
|
{mobileMenuTrigger}
|
2026-03-27 01:39:15 -07:00
|
|
|
{isChatPage && !isDocumentTab && searchSpaceId && (
|
2026-03-06 22:38:49 +05:30
|
|
|
<ChatHeader searchSpaceId={Number(searchSpaceId)} className="md:h-9 md:px-4 md:text-sm" />
|
|
|
|
|
)}
|
2026-01-08 19:10:40 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Right side - Actions */}
|
2026-03-31 21:29:46 -07:00
|
|
|
<div className="ml-auto flex items-center gap-2">
|
2026-01-20 16:33:42 +05:30
|
|
|
{hasThread && (
|
2026-01-20 20:47:31 +05:30
|
|
|
<ChatShareButton thread={threadForButton} onVisibilityChange={handleVisibilityChange} />
|
2026-01-20 16:14:57 +05:30
|
|
|
)}
|
2026-03-31 21:29:46 -07:00
|
|
|
{!isMobile && !hasTabBar && <RightPanelExpandButton />}
|
2026-01-08 19:10:40 +02:00
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
);
|
|
|
|
|
}
|