Files
DeepTutor/web/components/settings/SettingsMiniNav.tsx
Bingxi Zhao (Frank) 46093e5e2b update msg
2026-06-11 20:03:34 +08:00

90 lines
2.9 KiB
TypeScript

"use client";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { fetchAuthStatus } from "@/lib/auth";
import { SETTINGS_ITEMS } from "@/lib/settings-items";
export default function SettingsMiniNav() {
const pathname = usePathname();
const { t } = useTranslation();
// Only hide admin-only entries when we positively know the user is a
// non-admin; the backend rejects them regardless.
const [hideAdminOnly, setHideAdminOnly] = useState(false);
useEffect(() => {
let cancelled = false;
fetchAuthStatus().then((status) => {
if (cancelled || !status) return;
setHideAdminOnly(Boolean(status.enabled) && !status.is_admin);
});
return () => {
cancelled = true;
};
}, []);
const items = SETTINGS_ITEMS.filter(
(item) => !(item.adminOnly && hideAdminOnly),
);
return (
<aside className="flex h-full w-[248px] shrink-0 flex-col border-r border-[var(--border)] bg-[var(--card)]">
<div className="px-5 pb-4 pt-6">
<h1 className="font-serif text-[19px] font-semibold leading-tight tracking-tight text-[var(--foreground)]">
{t("Settings")}
</h1>
<p className="mt-1.5 text-[12.5px] leading-snug text-[var(--muted-foreground)]/80">
{t(
"Tune the app, configure model services, and inspect built-in tools.",
)}
</p>
</div>
<div
aria-hidden
className="mx-5 h-px bg-gradient-to-r from-transparent via-[var(--border)] to-transparent"
/>
<nav className="flex-1 px-2.5 py-3">
{items.map(({ href, label, description, icon: Icon }) => {
const active = pathname.startsWith(href);
return (
<Link
key={href}
href={href}
title={t(description)}
className={`group relative flex h-11 items-center gap-3 rounded-md px-3 transition-colors ${
active
? "bg-[var(--muted)]/70 text-[var(--foreground)]"
: "text-[var(--muted-foreground)] hover:bg-[var(--muted)]/40 hover:text-[var(--foreground)]"
}`}
>
{active && (
<span
aria-hidden
className="absolute left-0 top-1/2 h-5 w-[2.5px] -translate-y-1/2 rounded-r-full bg-[var(--foreground)]"
/>
)}
<Icon
size={17}
strokeWidth={active ? 2 : 1.7}
className="shrink-0"
/>
<span
className={`min-w-0 flex-1 truncate text-[14px] leading-none tracking-tight ${
active ? "font-medium" : "font-normal"
}`}
>
{t(label)}
</span>
</Link>
);
})}
</nav>
</aside>
);
}