2023-06-11 00:23:23 +04:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import Link from 'next/link'
|
2023-06-16 15:20:42 +04:00
|
|
|
import { usePathname } from 'next/navigation'
|
2023-06-11 00:23:23 +04:00
|
|
|
|
2023-06-16 15:20:42 +04:00
|
|
|
import { type Chat } from '@/lib/types'
|
2023-06-11 00:23:23 +04:00
|
|
|
import { cn } from '@/lib/utils'
|
2023-06-16 15:20:42 +04:00
|
|
|
import { buttonVariants } from '@/components/ui/button'
|
2023-06-16 16:18:52 +04:00
|
|
|
import { IconMessage, IconUsers } from '@/components/ui/icons'
|
|
|
|
|
import {
|
|
|
|
|
Tooltip,
|
|
|
|
|
TooltipContent,
|
|
|
|
|
TooltipTrigger
|
|
|
|
|
} from '@/components/ui/tooltip'
|
2023-06-11 00:23:23 +04:00
|
|
|
|
2023-06-14 16:39:55 +04:00
|
|
|
interface SidebarItemProps {
|
2023-06-16 15:20:42 +04:00
|
|
|
chat: Chat
|
|
|
|
|
children: React.ReactNode
|
2023-06-14 16:39:55 +04:00
|
|
|
}
|
|
|
|
|
|
2023-06-16 15:20:42 +04:00
|
|
|
export function SidebarItem({ chat, children }: SidebarItemProps) {
|
2023-06-11 00:23:23 +04:00
|
|
|
const pathname = usePathname()
|
2023-06-16 15:20:42 +04:00
|
|
|
const isActive = pathname === chat.path
|
2023-06-11 00:23:23 +04:00
|
|
|
|
2023-06-16 15:20:42 +04:00
|
|
|
if (!chat?.id) return null
|
2023-06-11 00:23:23 +04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Link
|
2023-06-16 17:06:23 +04:00
|
|
|
href={chat.path}
|
2023-06-11 00:23:23 +04:00
|
|
|
className={cn(
|
|
|
|
|
buttonVariants({ variant: 'ghost' }),
|
|
|
|
|
'group w-full px-2',
|
|
|
|
|
isActive && 'bg-accent'
|
|
|
|
|
)}
|
|
|
|
|
>
|
2023-06-16 16:18:52 +04:00
|
|
|
{chat.sharePath ? (
|
|
|
|
|
<Tooltip>
|
|
|
|
|
<TooltipTrigger>
|
|
|
|
|
<IconUsers className="mr-2" />
|
|
|
|
|
</TooltipTrigger>
|
|
|
|
|
<TooltipContent>This is a shared chat.</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
) : (
|
|
|
|
|
<IconMessage className="mr-2" />
|
|
|
|
|
)}
|
2023-06-11 00:23:23 +04:00
|
|
|
<div
|
2023-06-11 15:39:04 +04:00
|
|
|
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-11 00:23:23 +04:00
|
|
|
>
|
2023-06-16 15:20:42 +04:00
|
|
|
<span className="whitespace-nowrap">{chat.title}</span>
|
2023-06-11 00:23:23 +04:00
|
|
|
</div>
|
2023-06-16 17:06:23 +04:00
|
|
|
{isActive && children}
|
2023-06-11 00:23:23 +04:00
|
|
|
</Link>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|