-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.tsx
More file actions
151 lines (144 loc) · 4.46 KB
/
template.tsx
File metadata and controls
151 lines (144 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { getLogtoContext } from '@logto/next/server-actions';
import Link from 'next/link';
import { redirect } from 'next/navigation';
import type { ReactNode } from 'react';
import {
LuImage as ImageIcon,
LuBot,
LuFile,
LuHouse,
LuLogOut,
LuMenu,
LuMessageCircle,
LuMessageSquareHeart,
LuSettings,
LuShare,
} from 'react-icons/lu';
import KawaiiLogo from '@/assets/img/mikan-vtube.svg';
import { ChatSidebar } from '@/components/sidebar';
import { logtoConfig } from '@/lib/auth';
import { prisma } from '@/lib/prisma';
export default async function ChatLayout({
children,
}: {
children: ReactNode;
}) {
const { claims } = await getLogtoContext(logtoConfig);
if (!claims) {
await redirect('/login');
}
const account = await prisma.user.findUnique({
where: { id: claims?.sub },
});
if (!account) {
await prisma.user.create({
data: {
id: claims?.sub,
},
});
}
const chats = await prisma.chat.findMany({
where: { userId: claims?.sub || '' },
orderBy: {
createdAt: 'desc',
},
});
const data = {
user: {
name: claims?.name || '...',
id: claims?.sub || '...',
avatar: claims?.picture || '/default-avatar.png',
},
chats: chats.map((chat) => ({
name: chat.name || 'Untitled Chat',
id: chat.id,
})),
};
return (
<>
<div className="drawer">
<input className="drawer-toggle" id="my-drawer-3" type="checkbox" />
<div className="drawer-content flex flex-col">
<div className="navbar sticky top-0 z-40 w-full bg-base-300">
<div className="flex-none">
<label
aria-label="open sidebar"
className="btn btn-square btn-ghost"
htmlFor="my-drawer-3"
>
<LuMenu className="inline-block h-6 w-6" />
</label>
</div>
<div className="mx-2 flex-1 px-2">
<a className="flex space-x-3 font-bold text-xl normal-case">
<img
alt="MikanDev Logo"
className="mr-3 h-8 w-auto"
src={KawaiiLogo.src}
/>
Chat
</a>
</div>
<div className="hidden flex-none lg:block">
<ul className="menu menu-horizontal">
<Link href={'/settings/models'}>
<button className={'btn btn-ghost'}>
<LuBot className="inline-block h-6 w-6" />
Models
</button>
</Link>
<Link href={'/settings/files'}>
<button className={'btn btn-ghost'}>
<LuFile className="inline-block h-6 w-6" />
Files
</button>
</Link>
<Link href={'/settings/shared'}>
<button className={'btn btn-ghost'}>
<LuShare className="inline-block h-6 w-6" />
Shared chats
</button>
</Link>
<Link href={'/logout'} prefetch={false}>
<button className={'btn btn-ghost'}>
<LuLogOut className="inline-block h-6 w-6" />
Logout
</button>
</Link>
</ul>
</div>
</div>
{children}
</div>
<div className="drawer-side z-60">
<label
aria-label="close sidebar"
className="drawer-overlay"
htmlFor="my-drawer-3"
/>
<ul className="menu flex min-h-screen w-80 flex-col bg-base-200 p-4">
<ChatSidebar data={data} />
<div className="card mt-auto shadow-xl">
<div className="card-body">
<div className="flex items-center">
<div className="avatar">
<div className="w-12 rounded-full">
<img
alt={data.user.name}
src={data.user.avatar || '/default-avatar.png'}
/>
</div>
</div>
<div className="ml-3">
<h2 className="card-title">{data.user.name}</h2>
<p className="text-gray-500 text-sm">UID {data.user.id}</p>
</div>
</div>
</div>
</div>
</ul>
</div>
</div>
</>
);
}