import { Login } from '@/components/ui/login' import { NextChatLogo } from '@/components/ui/nextchat-logo' import { UserMenu } from '@/components/ui/user-menu' import { kv } from '@vercel/kv' import { Chat } from '@/lib/types' import { cn } from '@/lib/utils' import { type Session } from '@auth/nextjs/types' import { Plus } from 'lucide-react' import Link from 'next/link' import { ExternalLink } from './external-link' import { SidebarItem } from './sidebar-item' export interface SidebarProps { session?: Session newChat?: boolean } export function Sidebar({ session, newChat }: SidebarProps) { return (
) } Sidebar.displayName = 'Sidebar' async function SidebarList({ session }: { session?: Session }) { const results: Chat[] = await getChats(session?.user?.email ?? '') return results.map(c => ( )) } async function getChats(userId: string) { try { const pipeline = kv.pipeline() const chats: string[] = await kv.zrange(`user:chat:${userId}`, 0, -1) for (const chat of chats) { pipeline.hgetall(chat) } const results = await pipeline.exec() return results as Chat[] } catch (error) { return [] } }