Files

78 lines
2.3 KiB
TypeScript

import * as React from 'react'
import Link from 'next/link'
import { cn } from '@/lib/utils'
import { auth } from '@/auth'
import { clearChats } from '@/app/actions'
import { Button, buttonVariants } from '@/components/ui/button'
import { Sidebar } from '@/components/sidebar'
import { SidebarList } from '@/components/sidebar-list'
import {
IconGitHub,
IconLuxChat,
IconSeparator,
IconVercel
} from '@/components/ui/icons'
import { SidebarFooter } from '@/components/sidebar-footer'
import { ThemeToggle } from '@/components/theme-toggle'
import { ClearHistory } from '@/components/clear-history'
import { UserMenu } from '@/components/user-menu'
import { SidebarMobile } from './sidebar-mobile'
import { SidebarToggle } from './sidebar-toggle'
import { ChatHistory } from './chat-history'
async function SidebarOrLogin() {
const session = await auth()
return (
<>
{session?.user ? (
<>
<SidebarMobile>
<ChatHistory userId={session.user.id} />
</SidebarMobile>
<SidebarToggle />
</>
) : (
<Link href="/" target="_blank" rel="nofollow">
<IconLuxChat className="w-6 h-6 mr-2 dark:hidden" inverted />
<IconLuxChat className="hidden w-6 h-6 mr-2 dark:block" />
</Link>
)}
</>
)
}
async function UserOrLogin() {
const session = await auth()
return (
<>
<div className="flex items-center">
{session?.user ? (
<UserMenu user={session.user} />
) : (
<Button variant="default" asChild className="-ml-2">
<Link href="/sign-in?callbackUrl=/">Login</Link>
</Button>
)}
</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" />}>
<SidebarOrLogin />
</React.Suspense>
</div>
<div className="flex items-center justify-end space-x-2">
<React.Suspense fallback={<div className="flex-1 overflow-auto" />}>
<UserOrLogin />
</React.Suspense>
</div>
</header>
)
}