forked from vercel/ai-chatbot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsidebar-list.tsx
38 lines (34 loc) · 1.12 KB
/
sidebar-list.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { clearChats, getChats } from '@/app/actions'
import { ClearHistory } from '@/components/clear-history'
import { SidebarItems } from '@/components/sidebar-items'
import { ThemeToggle } from '@/components/theme-toggle'
import { cache } from 'react'
interface SidebarListProps {
userId?: string
children?: React.ReactNode
}
const loadChats = cache(async (userId?: string) => {
return await getChats(userId)
})
export async function SidebarList({ userId }: SidebarListProps) {
const chats = await loadChats(userId)
return (
<div className="flex flex-1 flex-col overflow-hidden">
<div className="flex-1 overflow-auto">
{chats?.length ? (
<div className="space-y-2 px-2">
<SidebarItems chats={chats} />
</div>
) : (
<div className="p-8 text-center">
<p className="text-sm text-muted-foreground">No chat history</p>
</div>
)}
</div>
<div className="flex items-center justify-between p-4">
<ThemeToggle />
<ClearHistory clearChats={clearChats} isEnabled={chats?.length > 0} />
</div>
</div>
)
}