import { useRef, useState } from "react"; import { type IUserStudyChapter, useLichess } from "#/hooks/useLichess.ts"; interface IProps { selectedStudyId: string; gameDispatch: any; } const SelectStudyChapter = ({ selectedStudyId, gameDispatch }: IProps) => { const [isOpen, setIsOpen] = useState(false); const [studyChapters, setStudyChapters] = useState([]); const dropdownRef = useRef(null); const { getLichessStudyChapters, loadLichessStudyChapter } = useLichess(); const onClickHandler = async () => { const studies = await getLichessStudyChapters({ studyId: selectedStudyId }); if (!studies) return; setStudyChapters(studies); setIsOpen(!isOpen); }; const handleChapterClick = async (chapter: IUserStudyChapter) => { const { headers, pgn } = await loadLichessStudyChapter({ chapter }); gameDispatch({ type: "SET_PGN", payload: headers, pgn }); setIsOpen(false); }; return (
{isOpen ? (
    {studyChapters?.map((chapter) => (
  • ))}
) : null}
); }; export default SelectStudyChapter;