import React, { useCallback } from "react"; import Dropdown from "../Shared/SettingsDropdown"; import Input from "@/components/Low/Input"; import ExercisePicker from "../../ExercisePicker"; import { generate } from "../Shared/Generate"; import GenerateBtn from "../Shared/GenerateBtn"; import { LevelPart, ReadingPart } from "@/interfaces/exam"; import { LevelSectionSettings, ReadingSectionSettings, } from "@/stores/examEditor/types"; import useExamEditorStore from "@/stores/examEditor"; interface Props { localSettings: ReadingSectionSettings | LevelSectionSettings; updateLocalAndScheduleGlobal: ( updates: Partial, schedule?: boolean ) => void; currentSection: ReadingPart | LevelPart; generatePassageDisabled?: boolean; levelId?: number; level?: boolean; } const ReadingComponents: React.FC = ({ localSettings, updateLocalAndScheduleGlobal, currentSection, levelId, level = false, generatePassageDisabled = false, }) => { const { currentModule } = useExamEditorStore(); const { focusedSection, difficulty } = useExamEditorStore( (state) => state.modules[currentModule] ); const generatePassage = useCallback(() => { generate( levelId ? levelId : focusedSection, "reading", "passage", { method: "GET", queryParams: { difficulty, ...(localSettings.readingTopic && { topic: localSettings.readingTopic, }), }, }, (data: any) => [ { title: data.title, text: data.text, }, ], level ? focusedSection : undefined, level ); // eslint-disable-next-line react-hooks/exhaustive-deps }, [localSettings.readingTopic, difficulty, focusedSection, levelId]); const onTopicChange = useCallback( (readingTopic: string) => { updateLocalAndScheduleGlobal({ readingTopic }); }, [updateLocalAndScheduleGlobal] ); return ( <> updateLocalAndScheduleGlobal({ isPassageOpen: isOpen }, false) } contentWrapperClassName={level ? `border border-ielts-reading` : ""} disabled={generatePassageDisabled} >
updateLocalAndScheduleGlobal({ isReadingTopicOpean: isOpen }) } contentWrapperClassName={level ? `border border-ielts-reading` : ""} disabled={ currentSection === undefined || currentSection.text === undefined || currentSection.text.content === "" || currentSection.text.title === "" } > ); }; export default ReadingComponents;