fix: update login button and sidebar

This commit is contained in:
shadcn 2023-06-13 18:14:06 +04:00
parent 5c2a3d4c3b
commit 282ef825cb
5 changed files with 72 additions and 40 deletions

View file

@ -1,13 +1,30 @@
import { getChats } from '@/app/actions'
import { Session } from '@auth/core/types'
import { SidebarItem } from './sidebar-item'
import { SidebarItem } from '@/components/sidebar-item'
import { LoginButton } from '@/components/login-button'
export interface SidebarListProps {
session?: Session
}
export async function SidebarList(props: SidebarListProps) {
const chats = await getChats(props.session?.user?.email)
export async function SidebarList({ session }: SidebarListProps) {
if (!session?.user?.email) {
return (
<div className="flex-1 p-6 flex text-sm items-center flex-col space-y-4">
<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>
)
}
const chats = await getChats(session.user.email)
return (
<div className="flex-1 overflow-auto">
{chats?.length ? (
@ -16,7 +33,7 @@ export async function SidebarList(props: SidebarListProps) {
<SidebarItem
key={chat.id}
title={chat.title}
userId={props?.session?.user?.email ?? ''}
userId={session?.user?.email ?? ''}
href={`/chat/${chat.id}`}
id={chat.id}
/>
@ -24,13 +41,7 @@ export async function SidebarList(props: SidebarListProps) {
</div>
) : (
<div className="p-8 text-center">
<p className="text-sm text-muted-foreground">
{props?.session?.user ? (
<>No chat history</>
) : (
<>Login for history</>
)}
</p>
<p className="text-sm text-muted-foreground">No chat history</p>
</div>
)}
</div>