Skip to content

An AI-powered search engine with a generative UI

Add SharePage component

Yoshiki Miuraea35044241f7
diff --git a/app/share/[id]/page.tsx b/app/share/[id]/page.tsx
new file mode 100644
index 00000000..0112f21f
--- /dev/null
+++ b/app/share/[id]/page.tsx
@@ -0,0 +1,38 @@
+import { notFound, redirect } from 'next/navigation'
+import { Chat } from '@/components/chat'
+import { getChat } from '@/lib/actions/chat'
+import { AI } from '@/app/actions'
+
+export const maxDuration = 60
+
+export interface SharePageProps {
+ params: {
+ id: string
+ }
+}
+
+export async function generateMetadata({ params }: SharePageProps) {
+ const chat = await getChat(params.id, 'anonymous')
+ return {
+ title: chat?.title.toString().slice(0, 50) || 'Search'
+ }
+}
+
+export default async function SharePage({ params }: SharePageProps) {
+ const userId = 'anonymous'
+ const chat = await getChat(params.id, userId)
+
+ if (!chat) {
+ redirect('/')
+ }
+
+ if (chat?.userId !== userId) {
+ notFound()
+ }
+
+ return (
+ <AI initialAIState={{ chatId: chat.id, messages: chat.messages }}>
+ <Chat id={params.id} />
+ </AI>
+ )
+}