2025-09-21 11:02:31 -07:00
|
|
|
"use client";
|
2024-11-05 14:16:27 +03:00
|
|
|
|
2025-09-21 11:02:31 -07:00
|
|
|
import Link from "next/link";
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
import { memo } from "react";
|
|
|
|
|
import { useWindowSize } from "usehooks-ts";
|
|
|
|
|
import { SidebarToggle } from "@/components/sidebar-toggle";
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { PlusIcon, VercelIcon } from "./icons";
|
|
|
|
|
import { useSidebar } from "./ui/sidebar";
|
|
|
|
|
import { VisibilitySelector, type VisibilityType } from "./visibility-selector";
|
2024-10-31 15:39:07 +05:30
|
|
|
|
2024-12-06 13:36:56 +03:00
|
|
|
function PureChatHeader({
|
|
|
|
|
chatId,
|
|
|
|
|
selectedVisibilityType,
|
|
|
|
|
isReadonly,
|
|
|
|
|
}: {
|
|
|
|
|
chatId: string;
|
|
|
|
|
selectedVisibilityType: VisibilityType;
|
|
|
|
|
isReadonly: boolean;
|
|
|
|
|
}) {
|
2024-11-06 22:10:15 +03:00
|
|
|
const router = useRouter();
|
2024-11-05 14:16:27 +03:00
|
|
|
const { open } = useSidebar();
|
|
|
|
|
|
|
|
|
|
const { width: windowWidth } = useWindowSize();
|
|
|
|
|
|
2024-10-24 16:35:51 -04:00
|
|
|
return (
|
2025-09-09 15:44:07 -04:00
|
|
|
<header className="sticky top-0 flex items-center gap-2 bg-background px-2 py-1.5 md:px-2">
|
2024-10-24 16:35:51 -04:00
|
|
|
<SidebarToggle />
|
2024-12-06 13:36:56 +03:00
|
|
|
|
2024-11-05 14:16:27 +03:00
|
|
|
{(!open || windowWidth < 768) && (
|
2025-09-07 00:04:51 +01:00
|
|
|
<Button
|
2026-03-13 13:12:33 -07:00
|
|
|
className="order-2 ml-auto md:order-1 md:ml-0"
|
2025-09-07 00:04:51 +01:00
|
|
|
onClick={() => {
|
2025-09-21 11:02:31 -07:00
|
|
|
router.push("/");
|
2025-09-07 00:04:51 +01:00
|
|
|
router.refresh();
|
|
|
|
|
}}
|
2026-03-13 13:12:33 -07:00
|
|
|
size="icon-sm"
|
2025-09-21 11:02:31 -07:00
|
|
|
variant="outline"
|
2025-09-07 00:04:51 +01:00
|
|
|
>
|
|
|
|
|
<PlusIcon />
|
|
|
|
|
<span className="md:sr-only">New Chat</span>
|
|
|
|
|
</Button>
|
2024-11-05 14:16:27 +03:00
|
|
|
)}
|
2024-12-06 13:36:56 +03:00
|
|
|
|
|
|
|
|
{!isReadonly && (
|
|
|
|
|
<VisibilitySelector
|
|
|
|
|
chatId={chatId}
|
2025-09-21 12:03:29 +01:00
|
|
|
className="order-1 md:order-2"
|
2025-09-21 11:02:31 -07:00
|
|
|
selectedVisibilityType={selectedVisibilityType}
|
2024-12-06 13:36:56 +03:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
2024-11-05 14:16:27 +03:00
|
|
|
<Button
|
2025-09-21 12:03:29 +01:00
|
|
|
asChild
|
2025-09-21 11:02:31 -07:00
|
|
|
className="order-3 hidden bg-zinc-900 px-2 text-zinc-50 hover:bg-zinc-800 md:ml-auto md:flex md:h-fit dark:bg-zinc-100 dark:text-zinc-900 dark:hover:bg-zinc-200"
|
2024-11-05 14:16:27 +03:00
|
|
|
>
|
|
|
|
|
<Link
|
2026-02-23 17:24:17 -08:00
|
|
|
href={"https://vercel.com/templates/next.js/chatbot"}
|
2025-09-21 12:03:29 +01:00
|
|
|
rel="noreferrer"
|
2025-09-21 11:02:31 -07:00
|
|
|
target="_noblank"
|
2024-11-05 14:16:27 +03:00
|
|
|
>
|
|
|
|
|
<VercelIcon size={16} />
|
|
|
|
|
Deploy with Vercel
|
|
|
|
|
</Link>
|
|
|
|
|
</Button>
|
2024-10-24 16:35:51 -04:00
|
|
|
</header>
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-12-03 17:49:38 +03:00
|
|
|
|
|
|
|
|
export const ChatHeader = memo(PureChatHeader, (prevProps, nextProps) => {
|
2025-09-01 11:07:07 +01:00
|
|
|
return (
|
|
|
|
|
prevProps.chatId === nextProps.chatId &&
|
|
|
|
|
prevProps.selectedVisibilityType === nextProps.selectedVisibilityType &&
|
|
|
|
|
prevProps.isReadonly === nextProps.isReadonly
|
|
|
|
|
);
|
2024-12-03 17:49:38 +03:00
|
|
|
});
|