import { XMarkIcon, BookOpenIcon } from "@heroicons/react/24/outline"; import { ChevronDownIcon, ClockIcon, PlayCircleIcon, } from "@heroicons/react/24/outline"; import { ChevronLeftIcon, ChevronRightIcon } from "@heroicons/react/24/outline"; import React, { useState, useRef, useContext } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { SectionDto, TaxonomySlug } from "@nice/common"; import { SyllabusHeader } from "./SyllabusHeader"; import { SectionItem } from "./SectionItem"; import { CollapsedButton } from "./CollapsedButton"; import { CourseDetailContext } from "../CourseDetailContext"; import { api } from "@nice/client"; interface CourseSyllabusProps { sections: SectionDto[]; onLectureClick?: (lectureId: string) => void; isOpen: boolean; onToggle: () => void; } export const CourseSyllabus: React.FC = ({ sections, onLectureClick, isOpen, onToggle, }) => { const { isHeaderVisible } = useContext(CourseDetailContext); const [expandedSections, setExpandedSections] = useState([]); const sectionRefs = useRef<{ [key: string]: HTMLDivElement | null }>({}); // api.term.findMany.useQuery({ // where: { // taxonomy: { slug: TaxonomySlug.CATEGORY }, // }, // }); const toggleSection = (sectionId: string) => { setExpandedSections((prev) => prev.includes(sectionId) ? prev.filter((id) => id !== sectionId) : [...prev, sectionId] ); setTimeout(() => { sectionRefs.current[sectionId]?.scrollIntoView({ behavior: "smooth", block: "start", }); }, 100); }; return ( <> {/* 收起时的悬浮按钮 */} {!isOpen && ( )} {isOpen && (
{sections.map((section, index) => ( (sectionRefs.current[ section.id ] = el) } index={index + 1} section={section} isExpanded={expandedSections.includes( section.id )} onToggle={toggleSection} onLectureClick={onLectureClick} /> ))}
)}
); };