"use client"; import { Accordion, AccordionContent, AccordionPanel, AccordionTitle, Modal, ModalBody, ModalHeader, } from "flowbite-react"; import Markdown from "markdown-to-jsx"; import { useEffect, useState } from "react"; import Styles from "./ChangelogModal.module.css"; import { tryCatch } from "#/api/utils"; export const ChangelogModal = (props: { isOpen: boolean; setIsOpen: any; version: string; previousVersions: Array; }) => { const [currentVersionChangelog, setCurrentVersionChangelog] = useState(""); const [previousVersionsChangelog, setPreviousVersionsChangelog] = useState< Record >({}); async function _fetchVersionChangelog(version: string) { const { data, error } = await tryCatch(fetch(`/changelog/${version}.md`)); if (error) { return "Нет списка изменений"; } return await data.text(); } useEffect(() => { if (props.version != "" && currentVersionChangelog == "") { setCurrentVersionChangelog("Загрузка ..."); _fetchVersionChangelog(props.version).then((data) => { setCurrentVersionChangelog(data); }); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.version]); return ( props.setIsOpen(false)}> Список изменений v{props.version} {currentVersionChangelog} {props.previousVersions.length > 0 && props.previousVersions.map((version) => { return ( { if (!previousVersionsChangelog.hasOwnProperty(version)) { _fetchVersionChangelog(version).then((data) => { setPreviousVersionsChangelog((prev) => { return { ...prev, [version]: data, }; }); }); } }} > Список изменений v{version} {previousVersionsChangelog.hasOwnProperty(version) ? {previousVersionsChangelog[version]} :
Загрузка ...
}
); })}
); };