2026-01-08 19:10:40 +02:00
|
|
|
"use client";
|
|
|
|
|
|
2026-01-20 16:33:42 +05:30
|
|
|
import { useAtomValue } from "jotai";
|
|
|
|
|
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";
|
|
|
|
|
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-01-20 16:33:42 +05:30
|
|
|
import type { ChatVisibility, ThreadRecord } from "@/lib/chat/thread-persistence";
|
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-01-20 20:47:31 +05:30
|
|
|
|
2026-01-20 16:14:57 +05:30
|
|
|
const isChatPage = pathname?.includes("/new-chat") ?? false;
|
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-01-20 16:33:42 +05:30
|
|
|
const hasThread = isChatPage && 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-07 02:34:23 +05:30
|
|
|
<header className="sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 bg-background/95 backdrop-blur supports-backdrop-filter:bg-background/60 px-4 md:border-b md:border-border">
|
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-06 22:38:49 +05:30
|
|
|
{isChatPage && searchSpaceId && (
|
|
|
|
|
<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-01-20 18:28:50 +05:30
|
|
|
<div className="flex items-center gap-4">
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|