feat(app): add error/loading boundaries and update dashboard routes

- Add error.tsx and loading.tsx boundaries for admin, parent, student, teacher routes

- Add dashboard-error-fallback and dashboard-loading-skeleton components

- Add student/learning page, parent/leave routes, teacher textbook components

- Update existing app routes across auth, dashboard, and API endpoints

- Update proxy middleware and next-auth type declarations
This commit is contained in:
SpecialX
2026-06-23 17:38:28 +08:00
parent c4d3433cc9
commit 1a9377222c
90 changed files with 1690 additions and 741 deletions

View File

@@ -24,7 +24,7 @@ export default async function StudentAssignmentTakePage({
const status = data.submission?.status
if (status === "graded" || status === "submitted") {
return (
<div className="h-full flex-1 flex-col space-y-8 p-8 md:flex">
<div className="space-y-8">
<div className="flex flex-col gap-1">
<h2 className="text-2xl font-bold tracking-tight">{data.assignment.title}</h2>
<div className="text-sm text-muted-foreground">
@@ -38,7 +38,7 @@ export default async function StudentAssignmentTakePage({
}
return (
<div className="flex h-full flex-col space-y-4 p-6">
<div className="space-y-4">
<div className="flex flex-col gap-1">
<h2 className="text-2xl font-bold tracking-tight">{data.assignment.title}</h2>
<div className="text-sm text-muted-foreground">

View File

@@ -6,6 +6,7 @@ import { Button } from "@/shared/components/ui/button"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { StatusBadge } from "@/shared/components/ui/status-badge"
import { formatDate, cn } from "@/shared/lib/utils"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
import { getStudentHomeworkAssignments } from "@/modules/homework/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
import { AssignmentFilters } from "@/modules/homework/components/assignment-filters"
@@ -20,13 +21,6 @@ import {
export const dynamic = "force-dynamic"
type SearchParams = { [key: string]: string | string[] | undefined }
const getParam = (params: SearchParams, key: string) => {
const v = params[key]
return Array.isArray(v) ? v[0] : v
}
const getActionLabel = (status: StudentHomeworkProgressStatus, t: (key: string) => string): string => {
switch (status) {
case "graded":

View File

@@ -3,7 +3,7 @@ import { Skeleton } from "@/shared/components/ui/skeleton"
export default function Loading() {
return (
<div className="flex h-full flex-col space-y-8 p-8">
<div className="space-y-8">
<div className="space-y-2">
<Skeleton className="h-8 w-40" />
<Skeleton className="h-4 w-52" />

View File

@@ -5,16 +5,10 @@ import { getCurrentStudentUser } from "@/modules/users/data-access"
import { StudentCoursesView } from "@/modules/student/components/student-courses-view"
import { CourseFilters } from "@/modules/student/components/course-filters"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const dynamic = "force-dynamic"
type SearchParams = { [key: string]: string | string[] | undefined }
const getParam = (params: SearchParams, key: string) => {
const v = params[key]
return Array.isArray(v) ? v[0] : v
}
export default async function StudentCoursesPage({
searchParams,
}: {

View File

@@ -0,0 +1,93 @@
import Link from "next/link"
import { BookOpen, PenTool, Library, ArrowRight } from "lucide-react"
import { getStudentClasses } from "@/modules/classes/data-access"
import { getStudentHomeworkAssignments } from "@/modules/homework/data-access"
import { getCurrentStudentUser } from "@/modules/users/data-access"
import { getTextbooks } from "@/modules/textbooks/data-access"
import { Card, CardContent, CardHeader, CardTitle } from "@/shared/components/ui/card"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { UserX } from "lucide-react"
export const dynamic = "force-dynamic"
export default async function StudentLearningPage() {
const student = await getCurrentStudentUser()
if (!student) {
return (
<div className="space-y-8">
<EmptyState title="No user found" description="Create a student user to see learning." icon={UserX} />
</div>
)
}
const [classes, assignments, textbooks] = await Promise.all([
getStudentClasses(student.id),
getStudentHomeworkAssignments(student.id),
getTextbooks(),
])
const now = new Date()
const pendingCount = assignments.filter((a) => a.progressStatus !== "submitted" && a.progressStatus !== "graded").length
const dueSoonCount = assignments.filter((a) => {
if (a.progressStatus === "submitted" || a.progressStatus === "graded") return false
if (!a.dueAt) return false
const due = new Date(a.dueAt)
const in7Days = new Date(now)
in7Days.setDate(in7Days.getDate() + 7)
return due >= now && due <= in7Days
}).length
const cards = [
{
title: "Courses",
description: "Your enrolled classes.",
icon: BookOpen,
href: "/student/learning/courses",
stat: `${classes.length} enrolled`,
},
{
title: "Assignments",
description: "Homework and practice.",
icon: PenTool,
href: "/student/learning/assignments",
stat: `${pendingCount} pending${dueSoonCount > 0 ? ` · ${dueSoonCount} due soon` : ""}`,
},
{
title: "Textbooks",
description: "Browse course materials.",
icon: Library,
href: "/student/learning/textbooks",
stat: `${textbooks.length} available`,
},
]
return (
<div className="space-y-8">
<div>
<h2 className="text-2xl font-bold tracking-tight">My Learning</h2>
<p className="text-muted-foreground">Your learning hub: courses, assignments, and textbooks.</p>
</div>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
{cards.map((c) => (
<Link key={c.href} href={c.href}>
<Card className="h-full transition-all hover:shadow-md hover:border-primary/50">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-base font-medium">{c.title}</CardTitle>
<c.icon className="h-5 w-5 text-muted-foreground" />
</CardHeader>
<CardContent className="space-y-2">
<p className="text-sm text-muted-foreground">{c.description}</p>
<div className="flex items-center justify-between">
<span className="text-sm font-medium">{c.stat}</span>
<ArrowRight className="h-4 w-4 text-muted-foreground" />
</div>
</CardContent>
</Card>
</Link>
))}
</div>
</div>
)
}

View File

@@ -3,8 +3,9 @@ import { getTranslations } from "next-intl/server"
import { BookOpen } from "lucide-react"
import { getTextbookById, getChaptersByTextbookId, getKnowledgePointsByTextbookId } from "@/modules/textbooks/data-access"
import { getTextbookById, getChaptersByTextbookId } from "@/modules/textbooks/data-access"
import { TextbookReader } from "@/modules/textbooks/components/textbook-reader"
import { getSubjectLabelKey, getGradeLabelKey } from "@/modules/textbooks/constants"
import { Badge } from "@/shared/components/ui/badge"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getCurrentStudentUser } from "@/modules/users/data-access"
@@ -23,10 +24,9 @@ export default async function StudentTextbookDetailPage({
const { id } = await params
const [textbook, chapters, knowledgePoints] = await Promise.all([
const [textbook, chapters] = await Promise.all([
getTextbookById(id),
getChaptersByTextbookId(id),
getKnowledgePointsByTextbookId(id)
])
if (!textbook) notFound()
@@ -45,9 +45,9 @@ export default async function StudentTextbookDetailPage({
<h1 className="text-lg font-bold tracking-tight truncate">{textbook.title}</h1>
<div className="flex items-center gap-2 text-sm text-muted-foreground">
<span className="hidden sm:inline-block w-px h-4 bg-border" aria-hidden="true" />
<Badge variant="outline" className="font-normal text-xs">{textbook.subject}</Badge>
<Badge variant="outline" className="font-normal text-xs">{t(`subject.${getSubjectLabelKey(textbook.subject)}`)}</Badge>
{textbook.grade && (
<Badge variant="secondary" className="font-normal text-xs">{textbook.grade}</Badge>
<Badge variant="secondary" className="font-normal text-xs">{t(`grade.${getGradeLabelKey(textbook.grade)}`)}</Badge>
)}
</div>
</div>
@@ -66,7 +66,7 @@ export default async function StudentTextbookDetailPage({
) : (
<div className="h-full min-h-0 max-w-[1600px] mx-auto w-full">
{/* 学生端不传 renderQuestionCreator无题目创建权限 */}
<TextbookReader chapters={chapters} knowledgePoints={knowledgePoints} />
<TextbookReader key={id} chapters={chapters} textbookId={id} />
</div>
)}
</div>

View File

@@ -7,16 +7,10 @@ import { TextbookFilters } from "@/modules/textbooks/components/textbook-filters
import { getCurrentStudentUser } from "@/modules/users/data-access"
import { getGradeNameById } from "@/modules/school/data-access"
import { EmptyState } from "@/shared/components/ui/empty-state"
import { getParam, type SearchParams } from "@/shared/lib/search-params"
export const dynamic = "force-dynamic"
type SearchParams = { [key: string]: string | string[] | undefined }
const getParam = (params: SearchParams, key: string): string | undefined => {
const v = params[key]
return Array.isArray(v) ? v[0] : v
}
export default async function StudentTextbooksPage({
searchParams,
}: {