chatbot-template/components/sidebar-item.tsx

45 lines
1.1 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 } from '@/components/ui/icons'
import { SidebarActions } from '@/components/sidebar-actions'
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 (
<>
<Link
2023-06-16 15:20:42 +04:00
href={chat.path || `/chat/${chat.id}`}
className={cn(
buttonVariants({ variant: 'ghost' }),
'group w-full px-2',
isActive && 'bg-accent'
)}
>
2023-06-13 16:02:07 +04:00
<IconMessage className="mr-2" />
<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>
2023-06-16 15:20:42 +04:00
{children}
</Link>
</>
)
}