import { use } from "react" import type { TeacherDashboardData } from "@/modules/dashboard/types" import type { TeacherDashboardMetrics } from "@/modules/dashboard/lib/dashboard-utils" import type { ActionState } from "@/shared/types/action-state" import { getTranslations } from "next-intl/server" import type { TeacherTodoItem } from "./teacher-todo-card" import { DashboardSection } from "../dashboard-section" import { TeacherClassesCard } from "./teacher-classes-card" import { TeacherDashboardHeader } from "./teacher-dashboard-header" import { TeacherHomeworkCard } from "./teacher-homework-card" import { RecentSubmissions } from "./recent-submissions" import { TeacherSchedule } from "./teacher-schedule" import { TeacherStats } from "./teacher-stats" import { TeacherGradeTrends } from "./teacher-grade-trends" import { TeacherTodoCard } from "./teacher-todo-card" type TeacherDashboardResult = ActionState /** * 教师仪表盘视图(P2-1 流式架构) * * 接收未解析的 Promise,用 React `use()` 消费。 * 页面外壳立即渲染,数据到达后在 DashboardSection 的 Suspense 边界内填充。 */ export function TeacherDashboardView({ dataPromise }: { dataPromise: Promise }) { const result = use(dataPromise) if (!result.success || !result.data) { throw new Error(result.message ?? "Failed to load teacher dashboard") } return } async function TeacherDashboardContent({ data }: { data: TeacherDashboardData & { metrics: TeacherDashboardMetrics } }) { const t = await getTranslations("dashboard") const { metrics } = data // 待办聚合(使用预计算指标) const todoItems: TeacherTodoItem[] = [ { label: t("todo.toGrade"), count: metrics.toGradeCount, href: "/teacher/homework/submissions", variant: metrics.toGradeCount > 0 ? "urgent" : "normal", }, { label: t("todo.todayAttendance"), count: metrics.todayScheduleItems.length, href: "/teacher/attendance/sheet", variant: "info", }, { label: t("todo.activeAssignments"), count: metrics.activeAssignmentsCount, href: "/teacher/homework/assignments", variant: "normal", }, ] return (
{/* 课表:移动端首位,桌面端右上 — 仅渲染一次(P2-9 修复,原为双实例) */}
) }