Skip to content

Commit 368ffbf

Browse files
committed
feat: error with types
1 parent 65e03c0 commit 368ffbf

3 files changed

Lines changed: 43 additions & 71 deletions

File tree

src/app/(public)/share/[id]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const ModelInfoFromID: Record<string, { name: string; description: string }> =
3737
export async function generateMetadata({
3838
params,
3939
}: { params: Promise<{ id: string }> }) {
40-
const id = (await params).id;
40+
const { id } = await params;
4141

4242
const chat = await prisma.chat.findUnique({
4343
where: { id },

src/app/(public)/template.tsx

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,13 @@ import {
33
SidebarInset,
44
SidebarTrigger,
55
} from "@/components/animate-ui/radix/sidebar";
6-
import { ChatSidebar } from "@/components/sidebar";
7-
import { getLogtoContext } from "@logto/next/server-actions";
8-
import { logtoConfig } from "@/lib/auth";
9-
import { prisma } from "@/lib/prisma";
106
import * as React from "react";
117

12-
export default async function ChatLayout({
8+
export default async function ShareLayout({
139
children,
1410
}: {
1511
children: React.ReactNode;
1612
}) {
17-
const { claims } = await getLogtoContext(logtoConfig);
18-
const chats = await prisma.chat.findMany({
19-
where: { userId: claims?.sub || "" },
20-
});
21-
22-
const data = {
23-
user: {
24-
name: claims?.name || "...",
25-
id: claims?.sub || "...",
26-
avatar: claims?.picture || "/default-avatar.png",
27-
},
28-
chats: chats.map((chat) => ({
29-
name: chat.name || "Untitled Chat",
30-
id: chat.id,
31-
})),
32-
};
3313

3414
return (
3515
<SidebarProvider>
Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,48 @@
1-
// src/app/(public)/share/[id]/page.tsx
21
import { prisma } from "@/lib/prisma";
3-
import { ChatPage } from "@/components/chat";
4-
import { notFound } from "next/navigation";
5-
import AIIcon from "@/assets/img/ai.png";
2+
import { getLogtoContext } from "@logto/next/server-actions";
3+
import { logtoConfig } from "@/lib/auth";
64

7-
export default async function SharedChatPage({
8-
params,
9-
}: { params: { id: string } }) {
10-
const { id } = params;
5+
import { redirect } from "next/navigation";
116

12-
// Fetch the chat and its messages
13-
const chat = await prisma.chat.findUnique({
14-
where: { id, public: true },
15-
include: { messages: { orderBy: { createdAt: "asc" } } },
16-
});
7+
export default async function Home() {
8+
const { claims } = await getLogtoContext(logtoConfig);
179

18-
if (!chat) {
19-
return notFound();
20-
}
10+
if (!claims) {
11+
await redirect("/login");
12+
}
2113

22-
// Format messages to match the expected structure by ChatPage
23-
const formattedMessages = chat.messages.map((msg) => ({
24-
id: msg.id,
25-
role: msg.role as "user" | "assistant" | "system",
26-
content: msg.content,
27-
parts: [{ type: "text", text: msg.content }],
28-
attachment: msg.attachmentId
29-
? {
30-
url: msg.attachmentId,
31-
name: msg.attachmentName || undefined,
32-
contentType: msg.attachmentType || undefined,
33-
}
34-
: undefined,
35-
}));
14+
const userSharedChats = await prisma.chat.findMany({
15+
where: { userId: claims?.sub, public: true },
16+
orderBy: { createdAt: "desc" },
17+
});
3618

37-
return (
38-
<div className="container mx-auto flex flex-col h-screen">
39-
<div className="bg-base-200 p-4 flex items-center">
40-
<h1 className="text-2xl font-bold">
41-
{chat.name || "Shared Chat"}
42-
</h1>
43-
<span className="ml-2 badge badge-primary">Read Only</span>
44-
</div>
45-
46-
<div className="flex-grow overflow-hidden">
47-
<ChatPage
48-
id={id}
49-
msg={formattedMessages}
50-
avatar="/avatar-placeholder.png" // Default avatar for shared chats
51-
status="ready"
52-
/>
53-
</div>
54-
</div>
55-
);
19+
return (
20+
<div className="container mx-auto p-4">
21+
<h1 className={"text-base-content text-4xl mb-4"}>Shared Chats</h1>
22+
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4">
23+
{userSharedChats.map((chat) => (
24+
<div
25+
key={chat.id}
26+
className="card bg-base-200 shadow-xl hover:shadow-2xl transition-shadow duration-300"
27+
>
28+
<div className="card-body">
29+
<h2 className="card-title">
30+
{chat.name || "Untitled Chat"}
31+
</h2>
32+
<p className="text-base-content/70">
33+
Created at:{" "}
34+
{new Date(chat.createdAt).toLocaleDateString()}
35+
</p>
36+
<a
37+
href={`/chat/${chat.id}`}
38+
className="btn btn-primary mt-4"
39+
>
40+
Open Chat
41+
</a>
42+
</div>
43+
</div>
44+
))}
45+
</div>
46+
</div>
47+
);
5648
}

0 commit comments

Comments
 (0)