chatbot-template/components/sidebar-item.tsx

63 lines
1.7 KiB
TypeScript
Raw Normal View History

'use client'
import Link from 'next/link'
2023-06-16 15:20:42 +04:00
import { usePathname } from 'next/navigation'
2023-06-16 15:20:42 +04:00
import { type Chat } from '@/lib/types'
import { cn } from '@/lib/utils'
2023-06-16 15:20:42 +04:00
import { buttonVariants } from '@/components/ui/button'
import { IconMessage, IconUsers } from '@/components/ui/icons'
import {
Tooltip,
TooltipContent,
TooltipTrigger
} from '@/components/ui/tooltip'
interface SidebarItemProps {
2023-06-16 15:20:42 +04:00
chat: Chat
children: React.ReactNode
}
2023-06-16 15:20:42 +04:00
export function SidebarItem({ chat, children }: SidebarItemProps) {
const pathname = usePathname()
2023-06-16 15:20:42 +04:00
const isActive = pathname === chat.path
2023-06-16 15:20:42 +04:00
if (!chat?.id) return null
return (
2023-06-17 00:16:42 +04:00
<div className="relative">
<div className="absolute left-2 top-1 flex h-6 w-6 items-center justify-center">
{chat.sharePath ? (
2023-06-17 00:16:42 +04:00
<Tooltip delayDuration={1000}>
<TooltipTrigger
tabIndex={-1}
className="focus:bg-muted focus:ring-1 focus:ring-ring"
>
<IconUsers className="mr-2" />
</TooltipTrigger>
<TooltipContent>This is a shared chat.</TooltipContent>
</Tooltip>
) : (
<IconMessage className="mr-2" />
)}
2023-06-17 00:16:42 +04:00
</div>
<Link
href={chat.path}
className={cn(
buttonVariants({ variant: 'ghost' }),
'group w-full pl-8 pr-16',
isActive && 'bg-accent'
)}
>
<div
className="relative max-h-5 flex-1 select-none overflow-hidden text-ellipsis break-all"
2023-06-16 15:20:42 +04:00
title={chat.title}
>
2023-06-16 15:20:42 +04:00
<span className="whitespace-nowrap">{chat.title}</span>
</div>
</Link>
2023-06-17 00:16:42 +04:00
{isActive && <div className="absolute right-2 top-1">{children}</div>}
</div>
)
}