-
-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathAdminShell.tsx
More file actions
217 lines (202 loc) · 6.46 KB
/
Copy pathAdminShell.tsx
File metadata and controls
217 lines (202 loc) · 6.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import {
Squares2X2Icon,
FlagIcon,
UsersIcon,
RssIcon,
TagIcon,
RectangleStackIcon,
ChartBarIcon,
ArrowLeftIcon,
} from "@heroicons/react/24/outline";
interface AdminUser {
name?: string | null;
image?: string | null;
}
interface NavItem {
name: string;
href: string;
icon: React.ComponentType<{ className?: string }>;
/** Planned surface that doesn't exist yet — rendered disabled with a badge. */
soon?: boolean;
}
// Sidebar sections. `soon` items are planned surfaces — shown as the
// roadmap but not linked until their routes exist.
const NAV: NavItem[] = [
{ name: "Overview", href: "/admin", icon: Squares2X2Icon },
{ name: "Moderation", href: "/admin/moderation", icon: FlagIcon },
{ name: "Users", href: "/admin/users", icon: UsersIcon },
{ name: "Sources", href: "/admin/sources", icon: RssIcon },
{ name: "Tags", href: "/admin/tags", icon: TagIcon },
{
name: "Content",
href: "/admin/content",
icon: RectangleStackIcon,
soon: true,
},
{ name: "Insights", href: "/admin/insights", icon: ChartBarIcon, soon: true },
];
/**
* The private admin cockpit shell: a persistent left sidebar + slim top bar +
* full-width fluid content area. Lives in the `(admin)` route group so it is
* fully outside the public `AppShell` rails. Reuses the Codú design tokens.
*/
export function AdminShell({
children,
user,
}: {
children: React.ReactNode;
user: AdminUser;
}) {
const pathname = usePathname();
const isActive = (href: string) =>
href === "/admin" ? pathname === "/admin" : pathname?.startsWith(href);
return (
<div className="flex min-h-svh bg-canvas text-fg">
{/* Desktop sidebar */}
<aside className="sticky top-0 hidden h-svh w-60 shrink-0 flex-col border-r border-hairline bg-surface md:flex">
<div className="flex h-14 items-center gap-2 px-4">
<span className="font-display text-lg font-extrabold tracking-tight text-fg">
Codú
</span>
<span className="rounded-sm border border-hairline px-1.5 py-px font-mono text-[10px] uppercase tracking-label text-faint">
Admin
</span>
</div>
<nav className="flex flex-1 flex-col gap-0.5 overflow-y-auto px-2 py-2">
{NAV.map((item) => (
<NavLink
key={item.name}
item={item}
active={!!isActive(item.href)}
/>
))}
</nav>
<Link
href="/"
className="flex items-center gap-2 border-t border-hairline px-4 py-3 text-sm text-muted transition-colors hover:text-fg"
>
<ArrowLeftIcon className="h-4 w-4" />
Back to site
</Link>
</aside>
<div className="flex min-w-0 flex-1 flex-col">
{/* Top bar */}
<header className="sticky top-0 z-20 flex h-14 items-center justify-between gap-3 border-b border-hairline bg-canvas/85 px-4 backdrop-blur sm:px-6">
<div className="flex items-center gap-2 md:hidden">
<span className="font-display text-base font-extrabold tracking-tight text-fg">
Codú
</span>
<span className="rounded-sm border border-hairline px-1.5 py-px font-mono text-[10px] uppercase tracking-label text-faint">
Admin
</span>
</div>
<p className="hidden font-mono text-xs uppercase tracking-label text-faint md:block">
{"// "}admin
</p>
<div className="flex items-center gap-3">
<Link
href="/"
className="hidden text-sm text-muted transition-colors hover:text-fg sm:block md:hidden"
>
Back to site
</Link>
<Avatar name={user.name} image={user.image} />
</div>
</header>
{/* Mobile horizontal nav (sidebar is hidden < md) */}
<nav className="flex gap-1 overflow-x-auto border-b border-hairline bg-surface px-3 py-2 md:hidden">
{NAV.map((item) => (
<MobileNavLink
key={item.name}
item={item}
active={!!isActive(item.href)}
/>
))}
</nav>
<main className="mx-auto w-full max-w-screen-2xl flex-1 px-4 py-6 sm:px-6 lg:px-8">
{children}
</main>
</div>
</div>
);
}
function NavLink({ item, active }: { item: NavItem; active: boolean }) {
const Icon = item.icon;
const base =
"flex items-center gap-2.5 rounded-md px-3 py-2 text-sm transition-colors duration-base ease-out";
if (item.soon) {
return (
<span
className={`${base} cursor-default font-medium text-faint`}
aria-disabled="true"
>
<Icon className="h-[18px] w-[18px]" />
<span className="flex-1">{item.name}</span>
<span className="rounded-sm border border-hairline px-1 py-px font-mono text-[9px] uppercase tracking-label text-faint">
Soon
</span>
</span>
);
}
return (
<Link
href={item.href}
aria-current={active ? "page" : undefined}
className={`${base} ${
active
? "bg-elevated font-semibold text-fg"
: "font-medium text-muted hover:bg-elevated hover:text-fg"
}`}
>
<Icon className="h-[18px] w-[18px]" />
{item.name}
</Link>
);
}
function MobileNavLink({ item, active }: { item: NavItem; active: boolean }) {
if (item.soon) {
return (
<span className="shrink-0 whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium text-faint">
{item.name}
</span>
);
}
return (
<Link
href={item.href}
aria-current={active ? "page" : undefined}
className={`shrink-0 whitespace-nowrap rounded-md px-3 py-1.5 text-sm transition-colors ${
active
? "bg-elevated font-semibold text-fg"
: "font-medium text-muted hover:bg-elevated hover:text-fg"
}`}
>
{item.name}
</Link>
);
}
function Avatar({
name,
image,
}: {
name?: string | null;
image?: string | null;
}) {
if (image) {
return (
<img
src={image}
alt={`${name ?? "Your"} avatar`}
className="h-8 w-8 rounded-full object-cover ring-2 ring-hairline"
/>
);
}
return (
<span className="flex h-8 w-8 items-center justify-center rounded-full bg-accent font-display text-sm font-bold text-on-accent">
{name?.[0]?.toUpperCase() || "C"}
</span>
);
}