Improve sidebar, new chat, and share dialog (#190)

This commit is contained in:
Jared Palmer 2023-12-04 12:42:53 -05:00 committed by GitHub
parent 35e83dc87e
commit be90a40427
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 598 additions and 217 deletions

View file

@ -0,0 +1,47 @@
import { type Metadata } from 'next'
import { notFound, redirect } from 'next/navigation'
import { auth } from '@/auth'
import { getChat } from '@/app/actions'
import { Chat } from '@/components/chat'
export interface ChatPageProps {
params: {
id: string
}
}
export async function generateMetadata({
params
}: ChatPageProps): Promise<Metadata> {
const session = await auth()
if (!session?.user) {
return {}
}
const chat = await getChat(params.id, session.user.id)
return {
title: chat?.title.toString().slice(0, 50) ?? 'Chat'
}
}
export default async function ChatPage({ params }: ChatPageProps) {
const session = await auth()
if (!session?.user) {
redirect(`/sign-in?next=/chat/${params.id}`)
}
const chat = await getChat(params.id, session.user.id)
if (!chat) {
notFound()
}
if (chat?.userId !== session?.user?.id) {
notFound()
}
return <Chat id={chat.id} initialMessages={chat.messages} />
}