2023-06-02 15:33:48 -04:00
|
|
|
import { type Metadata } from 'next'
|
2023-06-11 15:39:04 +04:00
|
|
|
|
2023-06-11 00:23:23 +04:00
|
|
|
import { Chat } from '@/components/chat'
|
2023-06-11 15:39:04 +04:00
|
|
|
import { getChat } from '@/app/actions'
|
2023-06-13 17:31:15 -04:00
|
|
|
import { Header } from '@/components/header'
|
|
|
|
|
import { auth } from '@clerk/nextjs'
|
2023-06-02 13:29:54 -04:00
|
|
|
|
2023-06-11 00:23:23 +04:00
|
|
|
// export const runtime = 'edge'
|
2023-06-02 15:33:48 -04:00
|
|
|
export const preferredRegion = 'home'
|
2023-06-11 00:23:23 +04:00
|
|
|
|
2023-05-19 12:33:56 -04:00
|
|
|
export interface ChatPageProps {
|
|
|
|
|
params: {
|
2023-06-02 15:33:48 -04:00
|
|
|
id: string
|
|
|
|
|
}
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function generateMetadata({
|
2023-06-02 15:33:48 -04:00
|
|
|
params
|
2023-05-19 12:33:56 -04:00
|
|
|
}: ChatPageProps): Promise<Metadata> {
|
2023-06-13 17:31:15 -04:00
|
|
|
const { user } = await auth()
|
|
|
|
|
const chat = await getChat(params.id, user?.id ?? '')
|
2023-05-19 12:33:56 -04:00
|
|
|
return {
|
2023-06-02 15:33:48 -04:00
|
|
|
title: chat?.title.slice(0, 50) ?? 'Chat'
|
|
|
|
|
}
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async function ChatPage({ params }: ChatPageProps) {
|
2023-06-13 17:31:15 -04:00
|
|
|
const { user } = await auth()
|
|
|
|
|
const chat = await getChat(params.id, user?.id ?? '')
|
2023-05-19 12:33:56 -04:00
|
|
|
|
2023-06-13 17:31:15 -04:00
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col min-h-screen">
|
|
|
|
|
{/* @ts-ignore */}
|
|
|
|
|
<Header />
|
|
|
|
|
<main className="flex-1 bg-muted/50">
|
|
|
|
|
<Chat id={chat.id} initialMessages={chat.messages} />
|
|
|
|
|
</main>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2023-06-02 15:15:35 -04:00
|
|
|
}
|