完整性更新

现在已经实现了大部分基础功能
This commit is contained in:
SpecialX
2026-01-08 11:14:03 +08:00
parent 0da2eac0b4
commit 57807def37
155 changed files with 26421 additions and 1036 deletions

View File

@@ -1,12 +1,14 @@
import { notFound } from "next/navigation";
import { ArrowLeft, Edit } from "lucide-react";
import { ArrowLeft } from "lucide-react";
import Link from "next/link";
import { Button } from "@/shared/components/ui/button";
import { Badge } from "@/shared/components/ui/badge";
import { getTextbookById, getChaptersByTextbookId, getKnowledgePointsByChapterId } from "@/modules/textbooks/data-access";
import { getTextbookById, getChaptersByTextbookId, getKnowledgePointsByTextbookId } from "@/modules/textbooks/data-access";
import { TextbookContentLayout } from "@/modules/textbooks/components/textbook-content-layout";
import { TextbookSettingsDialog } from "@/modules/textbooks/components/textbook-settings-dialog";
export const dynamic = "force-dynamic"
export default async function TextbookDetailPage({
params,
}: {
@@ -14,36 +16,16 @@ export default async function TextbookDetailPage({
}) {
const { id } = await params;
const [textbook, chapters] = await Promise.all([
const [textbook, chapters, knowledgePoints] = await Promise.all([
getTextbookById(id),
getChaptersByTextbookId(id),
getKnowledgePointsByTextbookId(id),
]);
if (!textbook) {
notFound();
}
// Fetch all KPs for these chapters. In a real app, this might be optimized to fetch only needed or use a different query strategy.
// For now, we simulate fetching KPs for all chapters to pass down, or we could fetch on demand.
// Given the layout loads everything client-side for interactivity, let's fetch all KPs associated with any chapter in this textbook.
// We'll need to extend the data access for this specific query pattern or loop.
// For simplicity in this mock, let's assume getKnowledgePointsByChapterId can handle fetching all KPs for a textbook if we had such a function,
// or we iterate. Let's create a helper to get all KPs for the textbook's chapters.
// Actually, let's update data-access to support getting KPs by Textbook ID directly or just fetch all for mock.
// Since we don't have getKnowledgePointsByTextbookId, we will map over chapters.
const allKnowledgePoints = (await Promise.all(
chapters.map(c => getKnowledgePointsByChapterId(c.id))
)).flat();
// Also need to get KPs for children chapters if any
const childrenKPs = (await Promise.all(
chapters.flatMap(c => c.children || []).map(child => getKnowledgePointsByChapterId(child.id))
)).flat();
const knowledgePoints = [...allKnowledgePoints, ...childrenKPs];
return (
<div className="flex flex-col h-[calc(100vh-4rem)] overflow-hidden">
{/* Header / Nav (Fixed height) */}

View File

@@ -1,20 +1,53 @@
import { Search, Filter } from "lucide-react";
import { Button } from "@/shared/components/ui/button";
import { Input } from "@/shared/components/ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/shared/components/ui/select";
import { Suspense } from "react"
import { BookOpen } from "lucide-react"
import { TextbookCard } from "@/modules/textbooks/components/textbook-card";
import { TextbookFormDialog } from "@/modules/textbooks/components/textbook-form-dialog";
import { getTextbooks } from "@/modules/textbooks/data-access";
import { TextbookFilters } from "@/modules/textbooks/components/textbook-filters"
import { EmptyState } from "@/shared/components/ui/empty-state"
export default async function TextbooksPage() {
// In a real app, we would parse searchParams here
const textbooks = await getTextbooks();
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
}
async function TextbooksResults({ searchParams }: { searchParams: Promise<SearchParams> }) {
const params = await searchParams
const q = getParam(params, "q") || undefined
const subject = getParam(params, "subject")
const grade = getParam(params, "grade")
const textbooks = await getTextbooks(q, subject || undefined, grade || undefined)
const hasFilters = Boolean(q || (subject && subject !== "all") || (grade && grade !== "all"))
if (textbooks.length === 0) {
return (
<EmptyState
icon={BookOpen}
title={hasFilters ? "No textbooks match your filters" : "No textbooks yet"}
description={hasFilters ? "Try clearing filters or adjusting keywords." : "Create your first textbook to start organizing chapters."}
action={hasFilters ? { label: "Clear filters", href: "/teacher/textbooks" } : undefined}
className="bg-card"
/>
)
}
return (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
{textbooks.map((textbook) => (
<TextbookCard key={textbook.id} textbook={textbook} />
))}
</div>
)
}
export default async function TextbooksPage({ searchParams }: { searchParams: Promise<SearchParams> }) {
return (
<div className="space-y-6">
@@ -29,50 +62,13 @@ export default async function TextbooksPage() {
<TextbookFormDialog />
</div>
{/* Toolbar */}
<div className="flex flex-col gap-4 md:flex-row md:items-center justify-between bg-card p-4 rounded-lg border shadow-sm">
<div className="relative w-full md:w-96">
<Search className="absolute left-2.5 top-2.5 h-4 w-4 text-muted-foreground" />
<Input
placeholder="Search textbooks..."
className="pl-9 bg-background"
/>
</div>
<div className="flex gap-2 w-full md:w-auto">
<Select>
<SelectTrigger className="w-[140px] bg-background">
<Filter className="mr-2 h-4 w-4 text-muted-foreground" />
<SelectValue placeholder="Subject" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All Subjects</SelectItem>
<SelectItem value="math">Mathematics</SelectItem>
<SelectItem value="physics">Physics</SelectItem>
<SelectItem value="history">History</SelectItem>
<SelectItem value="english">English</SelectItem>
</SelectContent>
</Select>
<Select>
<SelectTrigger className="w-[140px] bg-background">
<SelectValue placeholder="Grade" />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All Grades</SelectItem>
<SelectItem value="10">Grade 10</SelectItem>
<SelectItem value="11">Grade 11</SelectItem>
<SelectItem value="12">Grade 12</SelectItem>
</SelectContent>
</Select>
</div>
</div>
<Suspense fallback={<div className="h-14 w-full animate-pulse rounded-lg bg-muted" />}>
<TextbookFilters />
</Suspense>
{/* Grid Content */}
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
{textbooks.map((textbook) => (
<TextbookCard key={textbook.id} textbook={textbook} />
))}
</div>
<Suspense fallback={<div className="h-[360px] w-full animate-pulse rounded-md bg-muted" />}>
<TextbooksResults searchParams={searchParams} />
</Suspense>
</div>
);
}