2023-06-16 15:20:42 +04:00
|
|
|
import { getChats, removeChat, shareChat } from '@/app/actions'
|
|
|
|
|
import { SidebarActions } from '@/components/sidebar-actions'
|
2023-06-13 18:14:06 +04:00
|
|
|
|
|
|
|
|
import { SidebarItem } from '@/components/sidebar-item'
|
2023-06-11 11:14:39 -04:00
|
|
|
|
|
|
|
|
export interface SidebarListProps {
|
2023-06-13 17:31:15 -04:00
|
|
|
userId?: string
|
2023-06-11 11:14:39 -04:00
|
|
|
}
|
|
|
|
|
|
2023-06-13 17:31:15 -04:00
|
|
|
export async function SidebarList({ userId }: SidebarListProps) {
|
|
|
|
|
const chats = await getChats(userId)
|
2023-06-13 18:14:06 +04:00
|
|
|
|
2023-06-16 15:20:42 +04:00
|
|
|
console.log(chats)
|
|
|
|
|
|
2023-06-11 11:14:39 -04:00
|
|
|
return (
|
|
|
|
|
<div className="flex-1 overflow-auto">
|
|
|
|
|
{chats?.length ? (
|
2023-06-14 16:04:30 +04:00
|
|
|
<div className="space-y-2 px-2">
|
2023-06-16 15:20:42 +04:00
|
|
|
{chats.map(
|
|
|
|
|
chat =>
|
|
|
|
|
chat && (
|
|
|
|
|
<SidebarItem key={chat?.id} chat={chat}>
|
|
|
|
|
<SidebarActions
|
|
|
|
|
chat={chat}
|
|
|
|
|
removeChat={removeChat}
|
|
|
|
|
shareChat={shareChat}
|
|
|
|
|
/>
|
|
|
|
|
</SidebarItem>
|
|
|
|
|
)
|
|
|
|
|
)}
|
2023-06-11 11:14:39 -04:00
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
<div className="p-8 text-center">
|
2023-06-13 18:14:06 +04:00
|
|
|
<p className="text-sm text-muted-foreground">No chat history</p>
|
2023-06-11 11:14:39 -04:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|