diff --git a/src/app/(protected)/dashboard/layout.tsx b/src/app/(protected)/dashboard/layout.tsx index d64703f..6f30114 100644 --- a/src/app/(protected)/dashboard/layout.tsx +++ b/src/app/(protected)/dashboard/layout.tsx @@ -16,13 +16,6 @@ interface LayoutProps { children: React.ReactNode; } -interface WrongProblem { - id: string; - name: string; - status: string; - url?: string; -} - export default async function Layout({ children }: LayoutProps) { const session = await auth(); const user = session?.user; @@ -49,57 +42,14 @@ export default async function Layout({ children }: LayoutProps) { return ; case "STUDENT": default: - // 学生(STUDENT)需要查询错题数据 - return ; + return ; } }; - // 只有学生才需要查询错题数据 - let wrongProblemsData: WrongProblem[] = []; - if (fullUser.role === "STUDENT") { - // 查询未完成(未AC)题目的最新一次提交 - const wrongProblems = await prisma.problem.findMany({ - where: { - submissions: { - some: { userId: user.id }, - }, - NOT: { - submissions: { - some: { userId: user.id, status: "AC" }, - }, - }, - }, - select: { - id: true, - displayId: true, - localizations: { - where: { locale: "zh", type: "TITLE" }, - select: { content: true }, - }, - submissions: { - where: { userId: user.id }, - orderBy: { createdAt: "desc" }, - take: 1, - select: { - status: true, - }, - }, - }, - }); - - // 组装传递给 AppSidebar 的数据格式 - wrongProblemsData = wrongProblems.map((p) => ({ - id: p.id, - name: p.localizations[0]?.content || `题目${p.displayId}`, - status: p.submissions[0]?.status || "-", - url: `/problems/${p.id}`, - })); - } - return ( {fullUser.role === "STUDENT" ? ( - + ) : ( renderSidebar() )} diff --git a/src/app/(protected)/dashboard/page.tsx b/src/app/(protected)/dashboard/page.tsx index 4f01488..0d490e1 100644 --- a/src/app/(protected)/dashboard/page.tsx +++ b/src/app/(protected)/dashboard/page.tsx @@ -3,14 +3,10 @@ import { BookOpen, CheckCircle, Clock, - TrendingUp, AlertCircle, - BarChart3, Target, Activity, - GraduationCapIcon, } from "lucide-react"; -import Link from "next/link"; import { Card, CardContent, @@ -22,7 +18,6 @@ import prisma from "@/lib/prisma"; import { auth } from "@/lib/auth"; import { redirect } from "next/navigation"; import { Badge } from "@/components/ui/badge"; -import { Button } from "@/components/ui/button"; import { Progress } from "@/components/ui/progress"; interface Stats { @@ -206,28 +201,6 @@ export default async function DashboardPage() { color: "text-purple-600", }, ], - actions: [ - { - label: "管理员管理", - href: "/dashboard/management", - icon: Target, - }, - { - label: "学生管理", - href: "/dashboard/usermanagement/student", - icon: Users, - }, - { - label: "教师管理", - href: "/dashboard/usermanagement/teacher", - icon: GraduationCapIcon, - }, - { - label: "题目管理", - href: "/dashboard/usermanagement/problem", - icon: BookOpen, - }, - ], }; case "TEACHER": return { @@ -253,28 +226,6 @@ export default async function DashboardPage() { color: "text-purple-600", }, ], - actions: [ - { - label: "学生管理", - href: "/dashboard/usermanagement/student", - icon: Users, - }, - { - label: "题目管理", - href: "/dashboard/usermanagement/problem", - icon: BookOpen, - }, - { - label: "完成情况", - href: "/dashboard/teacher/dashboard", - icon: BarChart3, - }, - { - label: "课程管理", - href: "/dashboard/teacher/courses", - icon: BookOpen, - }, - ], }; default: return { @@ -300,20 +251,6 @@ export default async function DashboardPage() { color: "text-purple-600", }, ], - actions: [ - { - label: "我的进度", - href: "/dashboard/student/dashboard", - icon: TrendingUp, - }, - { - label: "我的课程", - href: "/dashboard/student/courses", - icon: GraduationCapIcon, - }, - { label: "开始做题", href: "/problemset", icon: BookOpen }, - { label: "个人设置", href: "/dashboard/management", icon: Target }, - ], }; } }; @@ -379,26 +316,6 @@ export default async function DashboardPage() { )} - {/* 快速操作 */} - - - 快速操作 - 常用功能快速访问 - - -
- {config.actions.map((action, index) => ( - - - - ))} -
-
-
- {/* 最近活动 */} diff --git a/src/components/nav-user.tsx b/src/components/nav-user.tsx index c2040d0..1e77cfc 100644 --- a/src/components/nav-user.tsx +++ b/src/components/nav-user.tsx @@ -10,15 +10,17 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, - DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu"; import { signOut } from "next-auth/react"; -import { useRouter } from "next/navigation"; -import { BadgeCheck, ChevronsUpDown, UserPen, LogOut } from "lucide-react"; +import { useTranslations } from "next-intl"; +import { ChevronsUpDown, LogOut } from "lucide-react"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; +import { SettingsButton } from "@/components/settings-button"; +import { DashboardButton } from "@/components/dashboard-button"; +import { DropdownMenuItem } from "@/components/ui/dropdown-menu"; export function NavUser({ user, @@ -30,7 +32,8 @@ export function NavUser({ }; }) { const { isMobile } = useSidebar(); - const router = useRouter(); + const t = useTranslations("UserAvatar"); + const avatarFallback = user.name?.charAt(0) || user.email?.charAt(0) || "U"; async function handleLogout() { await signOut({ @@ -39,14 +42,6 @@ export function NavUser({ }); } - function handleAccount() { - if (user && user.email) { - router.replace("/dashboard/management"); - } else { - router.replace("/sign-in"); - } - } - return ( @@ -58,7 +53,9 @@ export function NavUser({ > - CN + + {avatarFallback} +
{user.name} @@ -77,7 +74,9 @@ export function NavUser({
- CN + + {avatarFallback} +
{user.name} @@ -87,19 +86,13 @@ export function NavUser({ - - - 账号 - - router.push("/sign-in")}> - - 切换用户 - + + - 登出 + {t("LogOut")} diff --git a/src/components/sidebar/app-sidebar.tsx b/src/components/sidebar/app-sidebar.tsx index 1412781..96e9f77 100644 --- a/src/components/sidebar/app-sidebar.tsx +++ b/src/components/sidebar/app-sidebar.tsx @@ -14,7 +14,6 @@ import { User } from "next-auth"; import { siteConfig } from "@/config/site"; import { NavMain } from "@/components/nav-main"; import { NavUser } from "@/components/nav-user"; -import { NavProjects } from "@/components/nav-projects"; import { NavSecondary } from "@/components/nav-secondary"; import { Command, LifeBuoy, Send, Shield } from "lucide-react"; import { useTranslations } from "next-intl"; @@ -27,10 +26,6 @@ const data = { icon: Shield, isActive: true, items: [ - { - title: "我的进度", - url: "/dashboard/student/dashboard", - }, { title: "开始做题", url: "/problemset", @@ -39,6 +34,10 @@ const data = { title: "我的课程", url: "/dashboard/student/courses", }, + { + title: "我的进度", + url: "/dashboard/student/dashboard", + }, { title: "个人设置", url: "/dashboard/management", @@ -93,14 +92,9 @@ const data = { interface AppSidebarProps { user: User; - wrongProblems: { - id: string; - name: string; - status: string; - }[]; } -export function AppSidebar({ user, wrongProblems, ...props }: AppSidebarProps) { +export function AppSidebar({ user, ...props }: AppSidebarProps) { const t = useTranslations("Sidebar"); const userInfo = { name: user.name ?? "", @@ -129,7 +123,6 @@ export function AppSidebar({ user, wrongProblems, ...props }: AppSidebarProps) { -