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

@@ -1,15 +1,16 @@
import type { JSX, ReactNode } from "react"
import type { JSX } from "react"
import { notFound } from "next/navigation"
import { ArrowLeft } from "lucide-react"
import Link from "next/link"
import { getTranslations } from "next-intl/server"
import { Button } from "@/shared/components/ui/button"
import { Badge } from "@/shared/components/ui/badge"
import { getTextbookById, getChaptersByTextbookId, getKnowledgePointsByTextbookId } from "@/modules/textbooks/data-access"
import { TextbookReader, type TextbookReaderProps } from "@/modules/textbooks/components/textbook-reader"
import { getTextbookById, getChaptersByTextbookId } from "@/modules/textbooks/data-access"
import { TeacherTextbookReader } from "./_components/teacher-textbook-reader"
import { TextbookSettingsDialog } from "@/modules/textbooks/components/textbook-settings-dialog"
import { CreateQuestionDialog } from "@/modules/questions/components/create-question-dialog"
import type { KnowledgePoint } from "@/modules/textbooks/types"
import { getSubjectLabelKey, getGradeLabelKey } from "@/modules/textbooks/constants"
import { requirePermission } from "@/shared/lib/auth-guard"
import { Permissions } from "@/shared/types/permissions"
export const dynamic = "force-dynamic"
@@ -18,38 +19,20 @@ export default async function TextbookDetailPage({
}: {
params: Promise<{ id: string }>
}): Promise<JSX.Element> {
await requirePermission(Permissions.TEXTBOOK_READ)
const { id } = await params
const t = await getTranslations("textbooks")
const [textbook, chapters, knowledgePoints] = await Promise.all([
const [textbook, chapters] = await Promise.all([
getTextbookById(id),
getChaptersByTextbookId(id),
getKnowledgePointsByTextbookId(id),
])
if (!textbook) {
notFound()
}
// P0-1 在页面层注入 questions 模块的 CreateQuestionDialog 实现
const renderQuestionCreator: TextbookReaderProps["renderQuestionCreator"] = ({
open,
onOpenChange,
targetKp,
}: {
open: boolean
onOpenChange: (open: boolean) => void
targetKp: KnowledgePoint | null
}): ReactNode => (
<CreateQuestionDialog
open={open}
onOpenChange={onOpenChange}
defaultKnowledgePointIds={targetKp ? [targetKp.id] : []}
defaultContent={targetKp ? `Please explain the knowledge point: ${targetKp.name}` : ""}
defaultType="text"
/>
)
return (
<div className="flex flex-col h-[calc(100vh-4rem)] overflow-hidden">
{/* Header / Nav (Fixed height) */}
@@ -62,9 +45,9 @@ export default async function TextbookDetailPage({
</Button>
<div className="flex-1 min-w-0">
<div className="flex items-center gap-2 mb-1">
<Badge variant="outline">{textbook.subject}</Badge>
<Badge variant="outline">{t(`subject.${getSubjectLabelKey(textbook.subject)}`)}</Badge>
<span className="text-xs text-muted-foreground uppercase tracking-wider font-medium">
{textbook.grade}
{textbook.grade ? t(`grade.${getGradeLabelKey(textbook.grade)}`) : ""}
</span>
</div>
<h1 className="text-xl font-bold tracking-tight line-clamp-1">{textbook.title}</h1>
@@ -76,12 +59,7 @@ export default async function TextbookDetailPage({
{/* Main Content Layout (Flex grow) */}
<div className="flex-1 overflow-hidden pt-6">
<TextbookReader
chapters={chapters}
knowledgePoints={knowledgePoints}
textbookId={id}
renderQuestionCreator={renderQuestionCreator}
/>
<TeacherTextbookReader chapters={chapters} textbookId={id} />
</div>
</div>
)