feat(app): add error/loading boundaries across all dashboard routes and new routes
- Add error.tsx and loading.tsx boundaries for admin, parent, student, teacher routes - Add admin announcements edit, audit-logs overview, curriculum-map, invitation-codes, permissions, questions, roles routes - Add admin elective detail and components, files, course-plans, users, scheduling boundaries - Add messages group-compose route - Add parent course-plans, elective, grades report-card, practice routes - Add student course-plans, elective detail, error-book dialogs, grades report-card, learning study-path, leave, schedule boundaries - Add teacher attendance report, classes boundaries, course-plans boundaries, elective, exams analytics/edit-rich/all/create/new, grades report-card, homework boundaries, leave, lesson-plans calendar - Add auth loading, onboarding loading, api cron
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
import { Suspense } from "react"
|
||||
import type { JSX } from "react"
|
||||
import { getTranslations } from "next-intl/server"
|
||||
|
||||
import { requirePermission } from "@/shared/lib/auth-guard"
|
||||
import { Permissions } from "@/shared/types/permissions"
|
||||
import { getMessagesPageData } from "@/modules/messaging/data-access"
|
||||
import { MessageList } from "@/modules/messaging/components/message-list"
|
||||
import { SectionErrorBoundary } from "@/shared/components/section-error-boundary"
|
||||
import { getNotifications } from "@/modules/notifications/data-access"
|
||||
import { NotificationList } from "@/modules/notifications/components/notification-list"
|
||||
import { MessageListSection } from "@/modules/messaging/components/message-list-section"
|
||||
import { MessageListSkeleton } from "@/modules/messaging/components/message-list-skeleton"
|
||||
import { Card, CardContent, CardHeader } from "@/shared/components/ui/card"
|
||||
import { Skeleton } from "@/shared/components/ui/skeleton"
|
||||
|
||||
export const dynamic = "force-dynamic"
|
||||
|
||||
@@ -13,13 +19,40 @@ export async function generateMetadata() {
|
||||
return { title: t("title.list") }
|
||||
}
|
||||
|
||||
export default async function MessagesPage() {
|
||||
/**
|
||||
* P2-9: 通知列表区块骨架屏(Suspense fallback)。
|
||||
*/
|
||||
function NotificationListSkeleton(): JSX.Element {
|
||||
return (
|
||||
<div className="space-y-4" role="status" aria-label="Loading notifications">
|
||||
<Skeleton className="h-10 w-48" />
|
||||
{Array.from({ length: 3 }).map((_, i) => (
|
||||
<Card key={i} aria-hidden="true">
|
||||
<CardHeader className="space-y-2 pb-3">
|
||||
<Skeleton className="h-4 w-3/4" />
|
||||
<Skeleton className="h-3 w-1/2" />
|
||||
</CardHeader>
|
||||
<CardContent className="pt-0">
|
||||
<Skeleton className="h-3 w-full" />
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* P2-9: 通知列表区块(Server Component,流式加载)。
|
||||
*/
|
||||
async function NotificationListSection({ userId }: { userId: string }): Promise<JSX.Element> {
|
||||
const result = await getNotifications(userId, { page: 1, pageSize: 20 })
|
||||
return <NotificationList notifications={result.items} />
|
||||
}
|
||||
|
||||
export default async function MessagesPage(): Promise<JSX.Element> {
|
||||
const t = await getTranslations("messages")
|
||||
const ctx = await requirePermission(Permissions.MESSAGE_READ)
|
||||
|
||||
const { messages: messagesResult, notifications: notificationsResult } =
|
||||
await getMessagesPageData(ctx.userId)
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col space-y-8 p-8">
|
||||
<div>
|
||||
@@ -29,9 +62,19 @@ export default async function MessagesPage() {
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<MessageList messages={messagesResult.items} currentUserId={ctx.userId} />
|
||||
{/* P2-8 + P2-9: 消息列表区块独立 Suspense + ErrorBoundary,局部失败不影响通知区块 */}
|
||||
<Suspense fallback={<MessageListSkeleton />}>
|
||||
<SectionErrorBoundary namespace="messages">
|
||||
<MessageListSection userId={ctx.userId} canGroupSend={ctx.dataScope.type === "class_taught"} />
|
||||
</SectionErrorBoundary>
|
||||
</Suspense>
|
||||
|
||||
<NotificationList notifications={notificationsResult.items} />
|
||||
{/* P2-8 + P2-9: 通知列表区块独立 Suspense + ErrorBoundary */}
|
||||
<Suspense fallback={<NotificationListSkeleton />}>
|
||||
<SectionErrorBoundary namespace="notifications">
|
||||
<NotificationListSection userId={ctx.userId} />
|
||||
</SectionErrorBoundary>
|
||||
</Suspense>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user