chatbot-template/components/header.tsx

94 lines
3.5 KiB
TypeScript
Raw Normal View History

2023-06-16 17:06:23 +04:00
import { Suspense, use } from 'react'
2023-06-13 16:02:07 +04:00
import { cn } from '@/lib/utils'
import { buttonVariants } from '@/components/ui/button'
import { Sidebar } from '@/components/sidebar'
2023-06-13 16:02:07 +04:00
import { SidebarList } from '@/components/sidebar-list'
import { IconGitHub, IconSeparator, IconVercel } from '@/components/ui/icons'
2023-06-13 17:31:15 -04:00
import { UserButton, currentUser } from '@clerk/nextjs'
2023-06-16 15:20:42 +04:00
import { SidebarFooter } from '@/components/sidebar-footer'
import { ThemeToggle } from '@/components/theme-toggle'
import { ClearHistory } from '@/components/clear-history'
import { clearChats } from '@/app/actions'
2023-06-16 17:06:23 +04:00
import Link from 'next/link'
export async function Header() {
2023-06-13 17:31:15 -04:00
const user = await currentUser()
return (
2023-06-14 16:05:20 +04:00
<header className="sticky top-0 z-50 flex h-16 w-full shrink-0 items-center justify-between border-b bg-gradient-to-b from-background/10 via-background/50 to-background/80 px-4 backdrop-blur-xl">
<div className="flex items-center">
{/* @ts-ignore */}
2023-06-16 17:06:23 +04:00
{user?.id ? (
<Sidebar>
<Suspense fallback={<div className="flex-1 overflow-auto" />}>
{/* @ts-ignore */}
<SidebarList userId={user?.id} />
</Suspense>
<SidebarFooter>
<ThemeToggle />
<ClearHistory clearChats={clearChats} />
</SidebarFooter>
</Sidebar>
) : (
<Link href="https://vercel.com" target="_blank" rel="nofollow">
<IconVercel className="mr-2 h-6 w-6" />
</Link>
)}
2023-06-13 18:14:06 +04:00
<div className="flex items-center">
2023-06-14 16:05:20 +04:00
<IconSeparator className="h-6 w-6 text-muted-foreground/50" />
2023-06-16 17:06:23 +04:00
{user?.id ? (
<UserButton
showName
appearance={{
elements: {
avatarBox: 'w-6 h-6 rounded-full overflow-hidden',
userButtonBox: 'flex-row-reverse',
userButtonOuterIdentifier: 'text-primary',
userButtonPopoverCard:
'shadow-lg rounded-lg p-0 border border-border w-[200px] dark:bg-zinc-950 dark:text-zinc-50',
userButtonPopoverFooter:
'p-4 border-t border-border [&>*]:dark:text-zinc-600',
userPreview: 'p-4 border-b border-border m-0',
userButtonPopoverActionButton: 'px-1 gap-1',
userButtonPopoverActionButtonText:
'text-sm tracking-normal dark:text-zinc-400',
userButtonPopoverActionButtonIcon:
'h-4 w-4 text-muted-foreground'
}
}}
/>
) : (
<Link
href="/sign-in"
className={cn(buttonVariants({ variant: 'ghost' }))}
>
Sign in
</Link>
)}
</div>
</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-14 16:05:20 +04:00
<span className="ml-2 hidden md:flex">GitHub</span>
</a>
<a
href="https://github.com/vercel/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>
)
}