import { Button, Center, Modal, Space, Stepper, Title, Text, Flex, Select, Textarea, } from "@mantine/core"; import { useEffect, useState } from "react"; import "./NewMolecule.css"; import { IconArchiveFilled, IconArticleFilled, IconFileFilled, } from "@tabler/icons-react"; import { ConvertMoleculeToStandart, GetInFormats, } from "Api/ConvertBackendCalls"; import { AxiosError } from "axios"; import CustomButton from "Components/CustomButton/CustomButton"; interface NewMoleculeModalProps { isOpened: boolean; setIsOpened: (opened: boolean) => void; } export function NewMoleculeModal(props: NewMoleculeModalProps) { const [activeStep, setActiveStep] = useState(0); const [selectedMethod, setSelectedMethod] = useState(0); const [inMolecule, setInMolecule] = useState(""); const [inFormat, setInFormat] = useState(); const [inOptions, setInOptions] = useState(); const getOptions = () => { GetInFormats().then((data: { [key: string]: string } | AxiosError) => { if (data instanceof AxiosError) { //TODO: handle Error } else { const values = Object.keys(data); setInOptions(values); } }); }; useEffect(() => { getOptions(); }, []); //reset on open dialog useEffect(() => { if (props.isOpened) { setActiveStep(0); setSelectedMethod(0); setInMolecule(""); setInFormat(undefined); if (inOptions == undefined) { getOptions(); } } }, [props.isOpened]); const handleClose = () => { props.setIsOpened(false); }; const handleConvert = () => { if (inFormat) { ConvertMoleculeToStandart({ inputText: inMolecule, inputFormat: inFormat, make_3d: true, add_h: false, optimize: false, }).then((data: string | AxiosError) => { if (data instanceof AxiosError) { //TODO: handle Error } else { setCurrentMoleculeString(data); props.setIsOpened(false); } }); } else { //TODO: add no format selected handling } }; const handleEmptyMolecule = () => { props.setIsOpened(false); }; return ( Новая молекула centered size="75%" styles={{ content: { paddingLeft: "10px" }, title: { width: "100%" }, }} >
Шаг 1: Способ добавления молекулы
{selectedMethod == 2 && (
Шаг 2: Выбор файла
)} {selectedMethod == 3 && (
Шаг 2: Ввод молекулы