feat: 新增备课模块并修复全模块 P0/P1/P2 缺陷
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
Some checks failed
Security / deep-security-scan (push) Failing after 20m5s
DR Drill / dr-drill (push) Failing after 1m31s
CI / scheduled-backup (push) Failing after 1m31s
CI / backup-verify (push) Has been skipped
CI / weekly-dr-drill (push) Failing after 0s
CI / build-deploy (push) Has been cancelled
CI / security-scan (push) Has been cancelled
主要变更: - 新增 lesson-preparation 模块: 备课编辑器、节点编辑、AI 建议、知识点选择、版本历史、作业发布 - 新增 shared 通用组件: charts/question-bank-filters/schedule-list/ui (chip-nav/filter-bar/page-header/stat-card/stat-item) - 新增 student/admin 端 loading.tsx 与 error.tsx, 优化加载与错误态体验 - 新增 teacher/lesson-plans 页面 (列表/新建/编辑) - 新增 drizzle 迁移 0002_tiny_lionheart 及 snapshot - 新增 textbooks/schema.ts 与 exams/utils/normalize-structure.ts - 修复 Tiptap v3 SSR hydration 崩溃 (rich-text-block immediatelyRender: false) - 重构多模块 data-access/actions/组件, 修复权限校验与类型规范 - 同步架构文档 004/005 反映新增模块、导出、依赖关系 - 归档 bugs/* 测试报告与 e2e 测试脚本 (admin/parent/student/teacher web_test)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
"use client"
|
||||
|
||||
import Link from "next/link"
|
||||
import { useState } from "react"
|
||||
import { memo, useState, useTransition } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { toast } from "sonner"
|
||||
|
||||
@@ -16,6 +16,67 @@ import { BookOpen, Building2, Inbox, CalendarDays, User, PlusCircle, PenTool } f
|
||||
import type { StudentEnrolledClass } from "@/modules/classes/types"
|
||||
import { joinClassByInvitationCodeAction } from "@/modules/classes/actions"
|
||||
|
||||
const ClassCard = memo(function ClassCard({ c }: { c: StudentEnrolledClass }) {
|
||||
return (
|
||||
<Card className="flex flex-col overflow-hidden transition-all hover:shadow-md">
|
||||
<CardHeader className="bg-muted/30 pb-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="space-y-1">
|
||||
<CardTitle className="line-clamp-1 text-lg">{c.name}</CardTitle>
|
||||
<CardDescription className="flex items-center gap-2 text-xs">
|
||||
<span className="flex items-center gap-1">
|
||||
<BookOpen className="h-3 w-3" />
|
||||
Grade {c.grade}
|
||||
</span>
|
||||
{c.homeroom && (
|
||||
<>
|
||||
<span aria-hidden="true">•</span>
|
||||
<span>{c.homeroom}</span>
|
||||
</>
|
||||
)}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Badge variant="secondary" className="shrink-0">
|
||||
Active
|
||||
</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="flex-1 space-y-4 py-4">
|
||||
<div className="space-y-2 text-sm">
|
||||
{c.teacherName && (
|
||||
<div className="flex items-center gap-2 text-muted-foreground">
|
||||
<User className="h-4 w-4" />
|
||||
<span>{c.teacherName}</span>
|
||||
</div>
|
||||
)}
|
||||
{c.room && (
|
||||
<div className="flex items-center gap-2 text-muted-foreground">
|
||||
<Building2 className="h-4 w-4" />
|
||||
<span>Room {c.room}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
<CardFooter className="flex gap-2 border-t bg-muted/10 p-4">
|
||||
<Button asChild variant="outline" size="sm" className="flex-1">
|
||||
<Link href={`/student/schedule?classId=${encodeURIComponent(c.id)}`}>
|
||||
<CalendarDays className="mr-2 h-4 w-4" />
|
||||
Schedule
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild size="sm" className="flex-1">
|
||||
<Link href="/student/learning/assignments">
|
||||
<PenTool className="mr-2 h-4 w-4" />
|
||||
Assignments
|
||||
</Link>
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
)
|
||||
})
|
||||
|
||||
export function StudentCoursesView({
|
||||
classes,
|
||||
}: {
|
||||
@@ -23,24 +84,24 @@ export function StudentCoursesView({
|
||||
}) {
|
||||
const router = useRouter()
|
||||
const [code, setCode] = useState("")
|
||||
const [isWorking, setIsWorking] = useState(false)
|
||||
const [isPending, startTransition] = useTransition()
|
||||
|
||||
const handleJoin = async (formData: FormData) => {
|
||||
setIsWorking(true)
|
||||
try {
|
||||
const res = await joinClassByInvitationCodeAction(null, formData)
|
||||
if (res.success) {
|
||||
toast.success(res.message || "Joined class")
|
||||
setCode("")
|
||||
router.refresh()
|
||||
} else {
|
||||
toast.error(res.message || "Failed to join class")
|
||||
startTransition(async () => {
|
||||
try {
|
||||
const res = await joinClassByInvitationCodeAction(null, formData)
|
||||
if (res.success) {
|
||||
toast.success(res.message || "Joined class")
|
||||
setCode("")
|
||||
router.refresh()
|
||||
} else {
|
||||
toast.error(res.message || "Failed to join class")
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[joinClass] failed:", err)
|
||||
toast.error("Failed to join class")
|
||||
}
|
||||
} catch {
|
||||
toast.error("Failed to join class")
|
||||
} finally {
|
||||
setIsWorking(false)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -48,62 +109,7 @@ export function StudentCoursesView({
|
||||
{classes.length > 0 && (
|
||||
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-3">
|
||||
{classes.map((c) => (
|
||||
<Card key={c.id} className="flex flex-col overflow-hidden transition-all hover:shadow-md">
|
||||
<CardHeader className="bg-muted/30 pb-4">
|
||||
<div className="flex items-start justify-between gap-4">
|
||||
<div className="space-y-1">
|
||||
<CardTitle className="line-clamp-1 text-lg">{c.name}</CardTitle>
|
||||
<CardDescription className="flex items-center gap-2 text-xs">
|
||||
<span className="flex items-center gap-1">
|
||||
<BookOpen className="h-3 w-3" />
|
||||
Grade {c.grade}
|
||||
</span>
|
||||
{c.homeroom && (
|
||||
<>
|
||||
<span>•</span>
|
||||
<span>{c.homeroom}</span>
|
||||
</>
|
||||
)}
|
||||
</CardDescription>
|
||||
</div>
|
||||
<Badge variant="secondary" className="shrink-0">
|
||||
Active
|
||||
</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="flex-1 space-y-4 py-4">
|
||||
<div className="space-y-2 text-sm">
|
||||
{c.teacherName && (
|
||||
<div className="flex items-center gap-2 text-muted-foreground">
|
||||
<User className="h-4 w-4" />
|
||||
<span>{c.teacherName}</span>
|
||||
</div>
|
||||
)}
|
||||
{c.room && (
|
||||
<div className="flex items-center gap-2 text-muted-foreground">
|
||||
<Building2 className="h-4 w-4" />
|
||||
<span>Room {c.room}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
<CardFooter className="flex gap-2 border-t bg-muted/10 p-4">
|
||||
<Button asChild variant="outline" size="sm" className="flex-1">
|
||||
<Link href={`/student/schedule?classId=${encodeURIComponent(c.id)}`}>
|
||||
<CalendarDays className="mr-2 h-4 w-4" />
|
||||
Schedule
|
||||
</Link>
|
||||
</Button>
|
||||
<Button asChild size="sm" className="flex-1">
|
||||
<Link href={`/student/learning/assignments?classId=${encodeURIComponent(c.id)}`}>
|
||||
<PenTool className="mr-2 h-4 w-4" />
|
||||
Assignments
|
||||
</Link>
|
||||
</Button>
|
||||
</CardFooter>
|
||||
</Card>
|
||||
<ClassCard key={c.id} c={c} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
@@ -142,12 +148,13 @@ export function StudentCoursesView({
|
||||
value={code}
|
||||
onChange={(e) => setCode(e.target.value)}
|
||||
maxLength={6}
|
||||
pattern="\d{6}"
|
||||
className="max-w-md font-mono tracking-widest"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
<Button type="submit" disabled={isWorking} size="lg">
|
||||
{isWorking ? "Joining..." : "Join Class"}
|
||||
<Button type="submit" disabled={isPending} size="lg">
|
||||
{isPending ? "Joining..." : "Join Class"}
|
||||
</Button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user