chatbot-template/components/sidebar-list.tsx

39 lines
1.1 KiB
TypeScript
Raw Normal View History

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'
2023-06-11 11:14:39 -04:00
interface SidebarListProps {
2023-06-13 17:31:15 -04:00
userId?: string
children?: React.ReactNode
2023-06-11 11:14:39 -04:00
}
const loadChats = cache(async (userId?: string) => {
return await getChats(userId)
})
2023-06-13 17:31:15 -04:00
export async function SidebarList({ userId }: SidebarListProps) {
const chats = await loadChats(userId)
2023-06-13 18:14:06 +04:00
2023-06-11 11:14:39 -04:00
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>
2023-06-11 11:14:39 -04:00
</div>
)
}