chatbot-template/app/chat/[id]/page.tsx

56 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-05-19 12:33:56 -04:00
import { Sidebar } from "@/app/sidebar";
import { prisma } from "@/lib/prisma";
import { Chat } from "../../chat";
import { type Metadata } from "next";
import { getServerSession } from "@/lib/session/get-server-session";
2023-05-19 12:33:56 -04:00
export interface ChatPageProps {
params: {
id: string;
};
}
export async function generateMetadata({
params,
}: ChatPageProps): Promise<Metadata> {
const chat = await prisma.chat.findFirst({
where: {
id: params.id,
},
});
return {
title: chat?.title.slice(0, 50) ?? "Chat",
};
}
// Prisma does not support Edge without the Data Proxy currently
export const runtime = "nodejs"; // default
export const preferredRegion = "home";
export const dynamic = "force-dynamic";
export default async function ChatPage({ params }: ChatPageProps) {
const session = await getServerSession();
2023-05-19 12:33:56 -04:00
const chat = await prisma.chat.findFirst({
where: {
id: params.id,
},
include: {
messages: true,
},
});
if (!chat) {
throw new Error("Chat not found");
}
return (
<div className="relative flex h-full w-full overflow-hidden">
<Sidebar session={session} />
<div className="flex h-full min-w-0 flex-1 flex-col">
<Chat id={chat.id} messages={chat.messages} />
</div>
</div>
);
}
ChatPage.displayName = "ChatPage";