chatbot-template/components/sidebar-list.tsx

51 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-06-11 11:14:39 -04:00
import { getChats } from '@/app/actions'
2023-06-13 18:14:06 +04:00
import { SidebarItem } from '@/components/sidebar-item'
import { LoginButton } from '@/components/login-button'
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) {
if (!userId) {
2023-06-13 18:14:06 +04:00
return (
2023-06-13 17:31:15 -04:00
<div className="flex flex-col items-center flex-1 p-6 space-y-4 text-sm">
2023-06-13 18:14:06 +04:00
<div className="space-y-1 text-center">
<p className="font-medium">You are not logged in!</p>
<p className="text-muted-foreground">
Please login for chat history.
</p>
</div>
<LoginButton />
</div>
)
}
2023-06-13 17:31:15 -04:00
const chats = await getChats(userId)
2023-06-13 18:14:06 +04:00
2023-06-11 11:14:39 -04:00
return (
<div className="flex-1 overflow-auto">
{chats?.length ? (
<div className="px-2 space-y-2">
{chats.map(chat => (
<SidebarItem
key={chat.id}
title={chat.title}
2023-06-13 17:31:15 -04:00
userId={userId ?? ''}
2023-06-11 11:14:39 -04:00
href={`/chat/${chat.id}`}
id={chat.id}
/>
))}
</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>
)
}
SidebarList.displayName = 'SidebarList'