2025-03-17 16:58:22 -07:00
'use client' ;
2024-11-05 14:16:27 +03:00
2025-03-17 16:58:22 -07:00
import Link from 'next/link' ;
import { useRouter } from 'next/navigation' ;
import { useWindowSize } from 'usehooks-ts' ;
2024-10-24 16:35:51 -04:00
2025-03-17 16:58:22 -07:00
import { SidebarToggle } from '@/components/sidebar-toggle' ;
import { Button } from '@/components/ui/button' ;
import { PlusIcon , VercelIcon } from './icons' ;
import { useSidebar } from './ui/sidebar' ;
import { memo } from 'react' ;
2025-04-03 01:05:07 -07:00
import { type VisibilityType , VisibilitySelector } from './visibility-selector' ;
2025-04-25 23:40:15 -07:00
import type { Session } from 'next-auth' ;
2024-10-31 15:39:07 +05:30
2024-12-06 13:36:56 +03:00
function PureChatHeader ( {
chatId ,
selectedVisibilityType ,
isReadonly ,
2025-04-25 23:40:15 -07:00
session ,
2024-12-06 13:36:56 +03:00
} : {
chatId : string ;
selectedVisibilityType : VisibilityType ;
isReadonly : boolean ;
2025-04-25 23:40:15 -07:00
session : Session ;
2024-12-06 13:36:56 +03:00
} ) {
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
variant = "outline"
2025-09-09 22:19:34 +01:00
className = "order-2 ml-auto h-8 px-2 md:order-1 md:ml-0 md:h-fit md:px-2"
2025-09-07 00:04:51 +01:00
onClick = { ( ) = > {
router . push ( '/' ) ;
router . refresh ( ) ;
} }
>
< 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 }
selectedVisibilityType = { selectedVisibilityType }
2025-09-01 11:07:07 +01:00
className = "order-1 md:order-2"
2024-12-06 13:36:56 +03:00
/ >
) }
2024-11-05 14:16:27 +03:00
< Button
2025-09-09 22:19:34 +01: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
asChild
>
< Link
2025-09-09 13:03:52 -04:00
href = { ` https://vercel.com/new/clone?repository-url=https://github.com/vercel/ai-chatbot&env=AUTH_SECRET&envDescription=Learn more about how to get the API Keys for the application&envLink=https://github.com/vercel/ai-chatbot/blob/main/.env.example&demo-title=AI Chatbot&demo-description=An Open-Source AI Chatbot Template Built With Next.js and the AI SDK by Vercel.&demo-url=https://chat.vercel.ai&products=[{"type":"integration","protocol":"storage","productSlug":"neon","integrationSlug":"neon"},{"type":"integration","protocol":"storage","productSlug":"upstash-kv","integrationSlug":"upstash"},{"type":"blob"}] ` }
2024-11-05 14:16:27 +03:00
target = "_noblank"
>
< 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
} ) ;