import { Modal, Button, Accordion } from "flowbite-react"; import Markdown from "markdown-to-jsx"; import { useEffect, useState } from "react"; import Styles from "./ChangelogModal.module.css"; async function _fetchVersionChangelog(version: string) { const res = await fetch(`/changelog/${version}.md`); return await res.text(); } export const ChangelogModal = (props: { isOpen: boolean; setIsOpen: any; version: string; previousVersions: Array; }) => { const [currentVersionChangelog, setCurrentVersionChangelog] = useState(""); const [previousVersionsChangelog, setPreviousVersionsChangelog] = useState< Record >({}); useEffect(() => { _fetchVersionChangelog(props.version).then((data) => { setCurrentVersionChangelog(data); }); if (props.previousVersions.length > 0) { props.previousVersions.forEach((version) => { _fetchVersionChangelog(version).then((data) => { setPreviousVersionsChangelog((prev) => { return { ...prev, [version]: data, }; }); }); }); } }, [props.isOpen]); return ( props.setIsOpen(false)} > Список изменений v{props.version} {currentVersionChangelog} {Object.keys(previousVersionsChangelog).length > 0 && ( {Object.entries(previousVersionsChangelog).map( ([version, changelog]) => ( Список изменений v{version} {changelog} ) )} )} ); };