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-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 { NotificationButton } from "@/components/notifications/NotificationButton";
|
|
|
|
|
import type { ChatVisibility, ThreadRecord } from "@/lib/chat/thread-persistence";
|
2026-01-08 19:10:40 +02:00
|
|
|
|
|
|
|
|
interface HeaderProps {
|
|
|
|
|
breadcrumb?: React.ReactNode;
|
|
|
|
|
mobileMenuTrigger?: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Header({
|
|
|
|
|
breadcrumb,
|
|
|
|
|
mobileMenuTrigger,
|
|
|
|
|
}: HeaderProps) {
|
2026-01-20 16:14:57 +05:30
|
|
|
const pathname = usePathname();
|
|
|
|
|
|
|
|
|
|
// Check if we're on a chat page
|
|
|
|
|
const isChatPage = pathname?.includes("/new-chat") ?? false;
|
|
|
|
|
|
2026-01-20 16:33:42 +05:30
|
|
|
// Use Jotai atom for thread state (synced from chat page)
|
|
|
|
|
const currentThreadState = useAtomValue(currentThreadAtom);
|
|
|
|
|
|
|
|
|
|
// Show button only when we have a thread id (thread exists and is synced to Jotai)
|
|
|
|
|
const hasThread = isChatPage && currentThreadState.id !== null;
|
|
|
|
|
|
|
|
|
|
// Create minimal thread object for ChatShareButton (used for API calls)
|
|
|
|
|
const threadForButton: ThreadRecord | null = hasThread
|
|
|
|
|
? {
|
|
|
|
|
id: currentThreadState.id!,
|
|
|
|
|
visibility: currentThreadState.visibility ?? "PRIVATE",
|
|
|
|
|
// These fields are not used by ChatShareButton for display, only for checks
|
|
|
|
|
created_by_id: null,
|
|
|
|
|
search_space_id: 0,
|
|
|
|
|
title: "",
|
|
|
|
|
archived: false,
|
|
|
|
|
created_at: "",
|
|
|
|
|
updated_at: "",
|
|
|
|
|
}
|
2026-01-20 16:14:57 +05:30
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
const handleVisibilityChange = (visibility: ChatVisibility) => {
|
2026-01-20 16:33:42 +05:30
|
|
|
// Visibility change is handled by ChatShareButton internally via Jotai
|
2026-01-20 16:14:57 +05:30
|
|
|
// This callback can be used for additional side effects if needed
|
|
|
|
|
};
|
|
|
|
|
|
2026-01-08 19:10:40 +02:00
|
|
|
return (
|
|
|
|
|
<header className="sticky top-0 z-10 flex h-14 shrink-0 items-center gap-2 border-b bg-background/95 backdrop-blur supports-backdrop-filter:bg-background/60 px-4">
|
|
|
|
|
{/* Left side - Mobile menu trigger + Breadcrumb */}
|
|
|
|
|
<div className="flex flex-1 items-center gap-2 min-w-0">
|
|
|
|
|
{mobileMenuTrigger}
|
2026-01-11 16:08:23 +05:30
|
|
|
<div className="hidden md:block">{breadcrumb}</div>
|
2026-01-08 19:10:40 +02:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Right side - Actions */}
|
|
|
|
|
<div className="flex items-center gap-2">
|
2026-01-16 11:32:06 -08:00
|
|
|
{/* Notifications */}
|
|
|
|
|
<NotificationButton />
|
2026-01-20 16:14:57 +05:30
|
|
|
{/* Share button - only show on chat pages when thread exists */}
|
2026-01-20 16:33:42 +05:30
|
|
|
{hasThread && (
|
2026-01-20 16:14:57 +05:30
|
|
|
<ChatShareButton
|
2026-01-20 16:33:42 +05:30
|
|
|
thread={threadForButton}
|
2026-01-20 16:14:57 +05:30
|
|
|
onVisibilityChange={handleVisibilityChange}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-01-08 19:10:40 +02:00
|
|
|
</div>
|
|
|
|
|
</header>
|
|
|
|
|
);
|
|
|
|
|
}
|