chore: format code

This commit is contained in:
2026-03-11 00:18:12 +08:00
parent a3b9134299
commit 4d0c429d5f
12 changed files with 334 additions and 295 deletions

View File

@@ -1,25 +1,40 @@
'use client'
"use client";
import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { useState } from 'react'
import { CreditCard, Gear, ListCheck, Person, PlugConnection, Thunderbolt, Xmark, Bars } from '@gravity-ui/icons'
import SidebarFooter from '@/components/sidebar-footer'
import { useSession } from '@/lib/auth-client'
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useState } from "react";
import {
CreditCard,
Gear,
ListCheck,
Person,
PlugConnection,
Thunderbolt,
Xmark,
Bars,
} from "@gravity-ui/icons";
import SidebarFooter from "@/components/sidebar-footer";
import { useSession } from "@/lib/auth-client";
const navItems = [
{ href: '/dashboard', label: '概览', icon: Thunderbolt, exact: true, adminOnly: false },
{ href: '/dashboard/charge-points', label: '充电桩', icon: PlugConnection, adminOnly: false },
{ href: '/dashboard/transactions', label: '充电记录', icon: ListCheck, adminOnly: false },
{ href: '/dashboard/id-tags', label: '储值卡', icon: CreditCard, adminOnly: false },
{ href: '/dashboard/users', label: '用户管理', icon: Person, adminOnly: true },
]
{ href: "/dashboard", label: "概览", icon: Thunderbolt, exact: true, adminOnly: false },
{ href: "/dashboard/charge-points", label: "充电桩", icon: PlugConnection, adminOnly: false },
{ href: "/dashboard/transactions", label: "充电记录", icon: ListCheck, adminOnly: false },
{ href: "/dashboard/id-tags", label: "储值卡", icon: CreditCard, adminOnly: false },
{ href: "/dashboard/users", label: "用户管理", icon: Person, adminOnly: true },
];
const settingsItems = [
{ href: '/dashboard/settings', label: '账号设置', icon: Gear },
]
const settingsItems = [{ href: "/dashboard/settings", label: "账号设置", icon: Gear }];
function NavContent({ pathname, isAdmin, onNavigate }: { pathname: string; isAdmin: boolean; onNavigate?: () => void }) {
function NavContent({
pathname,
isAdmin,
onNavigate,
}: {
pathname: string;
isAdmin: boolean;
onNavigate?: () => void;
}) {
return (
<>
{/* Logo */}
@@ -37,70 +52,68 @@ function NavContent({ pathname, isAdmin, onNavigate }: { pathname: string; isAdm
<p className="mb-1 px-2 text-[11px] font-semibold uppercase tracking-widest text-muted">
</p>
{navItems.filter((item) => !item.adminOnly || isAdmin).map((item) => {
const isActive = item.exact
? pathname === item.href
: pathname === item.href || pathname.startsWith(item.href + '/')
const Icon = item.icon
return (
<Link
key={item.href}
href={item.href}
onClick={onNavigate}
className={[
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors',
isActive
? 'bg-accent/10 text-accent'
: 'text-muted hover:bg-surface-tertiary hover:text-foreground',
].join(' ')}
>
<Icon className="size-4 shrink-0" />
<span>{item.label}</span>
{isActive && (
<span className="ml-auto h-1.5 w-1.5 rounded-full bg-accent" />
)}
</Link>
)
})}
{navItems
.filter((item) => !item.adminOnly || isAdmin)
.map((item) => {
const isActive = item.exact
? pathname === item.href
: pathname === item.href || pathname.startsWith(item.href + "/");
const Icon = item.icon;
return (
<Link
key={item.href}
href={item.href}
onClick={onNavigate}
className={[
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors",
isActive
? "bg-accent/10 text-accent"
: "text-muted hover:bg-surface-tertiary hover:text-foreground",
].join(" ")}
>
<Icon className="size-4 shrink-0" />
<span>{item.label}</span>
{isActive && <span className="ml-auto h-1.5 w-1.5 rounded-full bg-accent" />}
</Link>
);
})}
<p className="mb-1 mt-3 px-2 text-[11px] font-semibold uppercase tracking-widest text-muted">
</p>
{settingsItems.map((item) => {
const isActive = pathname === item.href || pathname.startsWith(item.href + '/')
const Icon = item.icon
const isActive = pathname === item.href || pathname.startsWith(item.href + "/");
const Icon = item.icon;
return (
<Link
key={item.href}
href={item.href}
onClick={onNavigate}
className={[
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors',
"flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium transition-colors",
isActive
? 'bg-accent/10 text-accent'
: 'text-muted hover:bg-surface-tertiary hover:text-foreground',
].join(' ')}
? "bg-accent/10 text-accent"
: "text-muted hover:bg-surface-tertiary hover:text-foreground",
].join(" ")}
>
<Icon className="size-4 shrink-0" />
<span>{item.label}</span>
{isActive && (
<span className="ml-auto h-1.5 w-1.5 rounded-full bg-accent" />
)}
{isActive && <span className="ml-auto h-1.5 w-1.5 rounded-full bg-accent" />}
</Link>
)
);
})}
</nav>
{/* Footer */}
<SidebarFooter />
</>
)
);
}
export default function Sidebar() {
const pathname = usePathname()
const [open, setOpen] = useState(false)
const { data: sessionData } = useSession()
const isAdmin = sessionData?.user?.role === "admin"
const pathname = usePathname();
const [open, setOpen] = useState(false);
const { data: sessionData } = useSession();
const isAdmin = sessionData?.user?.role === "admin";
return (
<>
@@ -124,18 +137,15 @@ export default function Sidebar() {
{/* Mobile drawer overlay */}
{open && (
<div
className="fixed inset-0 z-40 bg-black/50 lg:hidden"
onClick={() => setOpen(false)}
/>
<div className="fixed inset-0 z-40 bg-black/50 lg:hidden" onClick={() => setOpen(false)} />
)}
{/* Mobile drawer */}
<aside
className={[
'fixed inset-y-0 left-0 z-50 flex w-64 flex-col border-r border-border bg-surface-secondary transition-transform duration-300 lg:hidden',
open ? 'translate-x-0' : '-translate-x-full',
].join(' ')}
"fixed inset-y-0 left-0 z-50 flex w-64 flex-col border-r border-border bg-surface-secondary transition-transform duration-300 lg:hidden",
open ? "translate-x-0" : "-translate-x-full",
].join(" ")}
>
<button
type="button"
@@ -153,5 +163,5 @@ export default function Sidebar() {
<NavContent pathname={pathname} isAdmin={isAdmin} />
</aside>
</>
)
);
}