feat: add admin accounts and image templates
This commit is contained in:
@@ -6,6 +6,7 @@ import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import {
|
||||
Archive,
|
||||
ShieldCheck,
|
||||
LogIn,
|
||||
LogOut,
|
||||
ScrollText,
|
||||
@@ -20,29 +21,33 @@ import type { AuthUser } from "@/lib/auth/session";
|
||||
const nav = [
|
||||
{ href: "/create", label: "创作", icon: Sparkles },
|
||||
{ href: "/assets", label: "结果", icon: Archive },
|
||||
{ href: "/logs", label: "日志", icon: ScrollText },
|
||||
{ href: "/settings", label: "设置", icon: Settings }
|
||||
{ href: "/logs", label: "日志", icon: ScrollText, adminOnly: true },
|
||||
{ href: "/settings", label: "设置", icon: Settings, adminOnly: true },
|
||||
{ href: "/accounts", label: "账号", icon: ShieldCheck, adminOnly: true }
|
||||
];
|
||||
|
||||
export function AppShell({
|
||||
children,
|
||||
user,
|
||||
authRequired
|
||||
authRequired,
|
||||
isAdmin
|
||||
}: {
|
||||
children: React.ReactNode;
|
||||
user?: AuthUser | null;
|
||||
authRequired?: boolean;
|
||||
isAdmin?: boolean;
|
||||
}) {
|
||||
const pathname = usePathname();
|
||||
const shellRef = useRef<HTMLDivElement | null>(null);
|
||||
const isAuthPage = pathname.startsWith("/auth");
|
||||
const isCreatePage = pathname === "/create";
|
||||
|
||||
useEffect(() => {
|
||||
return runScopedMotion(shellRef, (scope) => revealChildren(scope, "[data-shell-animate]"));
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className={clsx("app-shell", isAuthPage && "auth-shell")} ref={shellRef}>
|
||||
<div className={clsx("app-shell", isAuthPage && "auth-shell", isCreatePage && "create-shell")} ref={shellRef}>
|
||||
{!isAuthPage ? <a className="skip-link" href="#main-content">跳到主要内容</a> : null}
|
||||
{!isAuthPage ? (
|
||||
<header className="topbar" data-shell-animate>
|
||||
@@ -55,7 +60,7 @@ export function AppShell({
|
||||
</div>
|
||||
</Link>
|
||||
<nav className="nav top-nav" aria-label="主导航">
|
||||
{nav.map((item) => {
|
||||
{nav.filter((item) => !item.adminOnly || isAdmin).map((item) => {
|
||||
const Icon = item.icon;
|
||||
const active = item.href === "/" ? pathname === "/" : pathname.startsWith(item.href);
|
||||
return (
|
||||
@@ -93,7 +98,7 @@ export function AppShell({
|
||||
</div>
|
||||
</header>
|
||||
) : null}
|
||||
<main className={clsx("main", isAuthPage && "auth-main")} id="main-content" tabIndex={-1}>{children}</main>
|
||||
<main className={clsx("main", isAuthPage && "auth-main", isCreatePage && "create-main")} id="main-content" tabIndex={-1}>{children}</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user