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-30 01:50:41 +05:30
|
|
|
import { hitlEditPanelAtom } from "@/atoms/chat/hitl-edit-panel.atom";
|
2026-03-11 01:22:24 +05:30
|
|
|
import { reportPanelAtom } from "@/atoms/chat/report-panel.atom";
|
|
|
|
|
import { documentsSidebarOpenAtom } from "@/atoms/documents/ui.atoms";
|
2026-03-29 21:27:10 +05:30
|
|
|
import { editorPanelAtom } from "@/atoms/editor/editor-panel.atom";
|
2026-03-11 01:22:24 +05:30
|
|
|
import { rightPanelCollapsedAtom } from "@/atoms/layout/right-panel.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-29 21:27:10 +05:30
|
|
|
import { cn } from "@/lib/utils";
|
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);
|
|
|
|
|
const collapsed = useAtomValue(rightPanelCollapsedAtom);
|
|
|
|
|
const documentsOpen = useAtomValue(documentsSidebarOpenAtom);
|
|
|
|
|
const reportState = useAtomValue(reportPanelAtom);
|
|
|
|
|
const editorState = useAtomValue(editorPanelAtom);
|
|
|
|
|
const hitlEditState = useAtomValue(hitlEditPanelAtom);
|
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 reportOpen = reportState.isOpen && !!reportState.reportId;
|
|
|
|
|
const editorOpen = editorState.isOpen && !!editorState.documentId;
|
|
|
|
|
const hitlEditOpen = hitlEditState.isOpen && !!hitlEditState.onSave;
|
2026-03-30 01:50:41 +05:30
|
|
|
const showExpandButton =
|
|
|
|
|
!isMobile && collapsed && (documentsOpen || reportOpen || editorOpen || hitlEditOpen);
|
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-30 01:50:41 +05:30
|
|
|
<div
|
|
|
|
|
className={cn("ml-auto flex items-center gap-2", showExpandButton && !hasTabBar && "mr-10")}
|
|
|
|
|
>
|
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-01-08 19:10:40 +02:00
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
);
|
|
|
|
|
}
|