"use client"; /** * textbook-manager(teacher / main) * * 教材管理:按科目与年级筛选教材,点击教材查看章节列表。 * 通过 useWidgetQuery 查询 apollo-router → content 子图的 textbooks 数据。 * * 关联:portal-shell spec §5.6 统一 Hook */ import { useState } from "react"; import { useTextbooks } from "@/lib/api"; import { PluginSkeleton } from "@/shell/PluginLoader"; import type { PluginProps } from "@/lib/types"; export default function TextbookManager( _props: PluginProps, ): React.ReactElement { const [subjectInput, setSubjectInput] = useState(""); const [gradeInput, setGradeInput] = useState(""); const [appliedSubject, setAppliedSubject] = useState(""); const [appliedGrade, setAppliedGrade] = useState(""); const [selectedId, setSelectedId] = useState(null); const { data, loading } = useTextbooks({ subjectId: appliedSubject || undefined, grade: appliedGrade || undefined, }); if (loading && !data) { return ; } const textbooks = data ?? []; const selected = textbooks.find((t) => t.id === selectedId) ?? null; const handleApply = (): void => { setAppliedSubject(subjectInput.trim()); setAppliedGrade(gradeInput.trim()); setSelectedId(null); }; return (

教材管理

    {textbooks.length === 0 ? (
  • 暂无教材数据
  • ) : ( textbooks.map((t) => (
  • )) )}
{selected ? (

{selected.title}

{selected.author} · {selected.publisher}

章节列表
    {selected.chapters.map((c, i) => (
  1. {i + 1}. {c.title}
  2. ))}
) : (
点击左侧教材查看章节
)}
); }