chatbot-template/components/header.tsx

81 lines
2.5 KiB
TypeScript
Raw Normal View History

2023-06-16 21:52:01 +04:00
import * as React from 'react'
import Link from 'next/link'
2023-06-13 16:02:07 +04:00
import { cn } from '@/lib/utils'
2023-06-16 21:52:01 +04:00
import { auth } from '@/auth'
2023-06-21 14:42:18 -07:00
import { Button, buttonVariants } from '@/components/ui/button'
2023-06-16 22:39:09 +04:00
import {
IconGitHub,
IconNextChat,
IconSeparator,
IconVercel
} from '@/components/ui/icons'
2023-06-16 21:52:01 +04:00
import { UserMenu } from '@/components/user-menu'
import { SidebarMobile } from './sidebar-mobile'
import { SidebarToggle } from './sidebar-toggle'
import { ChatHistory } from './chat-history'
2024-03-14 20:00:52 +03:00
import { Session } from '@/lib/types'
2023-11-26 18:30:48 -06:00
async function UserOrLogin() {
2024-03-14 20:00:52 +03:00
const session = (await auth()) as Session
return (
2023-11-26 18:30:48 -06:00
<>
{session?.user ? (
<>
<SidebarMobile>
<ChatHistory userId={session.user.id} />
</SidebarMobile>
<SidebarToggle />
</>
2023-11-26 18:30:48 -06:00
) : (
2024-03-14 20:00:52 +03:00
<Link href="/" rel="nofollow">
2024-01-20 10:39:02 -06:00
<IconNextChat className="size-6 mr-2 dark:hidden" inverted />
<IconNextChat className="hidden size-6 mr-2 dark:block" />
2023-11-26 18:30:48 -06:00
</Link>
)}
<div className="flex items-center">
2024-01-20 10:39:02 -06:00
<IconSeparator className="size-6 text-muted-foreground/50" />
2023-06-16 11:49:14 -04:00
{session?.user ? (
2023-11-26 18:30:48 -06:00
<UserMenu user={session.user} />
2023-06-16 17:06:23 +04:00
) : (
2023-11-26 18:30:48 -06:00
<Button variant="link" asChild className="-ml-2">
2024-03-14 20:00:52 +03:00
<Link href="/login">Login</Link>
2023-11-26 18:30:48 -06:00
</Button>
2023-06-16 17:06:23 +04:00
)}
2023-11-26 18:30:48 -06:00
</div>
</>
)
}
export function Header() {
return (
<header className="sticky top-0 z-50 flex items-center justify-between w-full h-16 px-4 border-b shrink-0 bg-gradient-to-b from-background/10 via-background/50 to-background/80 backdrop-blur-xl">
<div className="flex items-center">
<React.Suspense fallback={<div className="flex-1 overflow-auto" />}>
<UserOrLogin />
</React.Suspense>
</div>
<div className="flex items-center justify-end space-x-2">
<a
target="_blank"
href="https://github.com/vercel/nextjs-ai-chatbot/"
rel="noopener noreferrer"
className={cn(buttonVariants({ variant: 'outline' }))}
>
2023-06-13 18:14:06 +04:00
<IconGitHub />
2023-06-21 14:42:18 -07:00
<span className="hidden ml-2 md:flex">GitHub</span>
</a>
<a
2024-03-14 20:00:52 +03:00
href="https://vercel.com/templates/Next.js/nextjs-ai-chatbot"
target="_blank"
className={cn(buttonVariants())}
>
2023-06-13 18:14:06 +04:00
<IconVercel className="mr-2" />
<span className="hidden sm:block">Deploy to Vercel</span>
2023-06-11 23:07:49 +04:00
<span className="sm:hidden">Deploy</span>
</a>
</div>
</header>
)
}