2023-06-16 16:18:52 +04:00
|
|
|
import { type Metadata } from 'next'
|
|
|
|
|
import { notFound } from 'next/navigation'
|
|
|
|
|
|
2023-06-16 17:06:23 +04:00
|
|
|
import { formatDate } from '@/lib/utils'
|
|
|
|
|
import { getSharedChat } from '@/app/actions'
|
|
|
|
|
import { ChatList } from '@/components/chat-list'
|
|
|
|
|
import { FooterText } from '@/components/footer'
|
|
|
|
|
|
2023-06-16 18:41:22 +04:00
|
|
|
interface SharePageProps {
|
2023-06-16 16:18:52 +04:00
|
|
|
params: {
|
|
|
|
|
id: string
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function generateMetadata({
|
|
|
|
|
params
|
|
|
|
|
}: SharePageProps): Promise<Metadata> {
|
2023-06-16 17:06:23 +04:00
|
|
|
const chat = await getSharedChat(params.id)
|
|
|
|
|
|
2023-06-16 16:18:52 +04:00
|
|
|
return {
|
|
|
|
|
title: chat?.title.slice(0, 50) ?? 'Chat'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default async function SharePage({ params }: SharePageProps) {
|
|
|
|
|
const chat = await getSharedChat(params.id)
|
|
|
|
|
|
|
|
|
|
if (!chat || !chat?.sharePath) {
|
|
|
|
|
notFound()
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-16 17:06:23 +04:00
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<div className="flex-1 space-y-6">
|
2023-06-21 08:23:16 -07:00
|
|
|
<div className="px-4 py-6 border-b bg-background md:px-6 md:py-8">
|
|
|
|
|
<div className="max-w-2xl mx-auto md:px-6">
|
|
|
|
|
<div className="space-y-1 md:-mx-8">
|
2023-06-16 17:06:23 +04:00
|
|
|
<h1 className="text-2xl font-bold">{chat.title}</h1>
|
|
|
|
|
<div className="text-sm text-muted-foreground">
|
|
|
|
|
{formatDate(chat.createdAt)} · {chat.messages.length} messages
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<ChatList messages={chat.messages} />
|
|
|
|
|
</div>
|
|
|
|
|
<FooterText className="py-8" />
|
|
|
|
|
</>
|
|
|
|
|
)
|
2023-06-16 16:18:52 +04:00
|
|
|
}
|