import { File, Modpack } from '@/api/server/modpacks/Modpack'; import GreyRowBox from '@/components/elements/GreyRowBox'; import TitledGreyBox from '@/components/elements/TitledGreyBox'; import React from 'react'; import ModpackModal from './ModpackModal'; import Button from '@/components/elements/Button'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faDownload, faGamepad } from '@fortawesome/free-solid-svg-icons'; import getModpackDescription from '@/api/server/modpacks/getModpackDescription'; import { ServerContext } from '@/state/server'; import { get } from 'http'; import pullFile from '@/api/server/files/pullFile'; import getFileExists from '@/api/server/files/getFileExists'; import Spinner from '@/components/elements/Spinner'; import decompressFiles from '@/api/server/files/decompressFiles'; interface Props { modpack: Modpack; } export default ({ modpack }: Props) => { const uuid = ServerContext.useStoreState((state) => state.server.data!.uuid); const [visible, setVisible] = React.useState(false); const [installVisible, setInstallVisible] = React.useState(false); const [modpackDesc, setModpackDesc] = React.useState(''); const [installing, setInstalling] = React.useState(false); const openModal = (): void => { setVisible(true); }; const openInstallModal = (): void => { setInstallVisible(true); }; const install = async (latestFile: File): Promise => { setInstalling(true); pullFile(uuid, { url: latestFile.downloadUrl, directory: '/home/container', filename: 'modpack.zip', use_header: true, foreground: true, }); let modpackDownloaded = await getFileExists(uuid, '/home/container/modpack.zip'); while (!modpackDownloaded) { modpackDownloaded = await getFileExists(uuid, '/home/container/modpack.zip'); } decompressFiles(uuid, '/home/container/modpack', '/home/container/modpack.zip'); setInstalling(false); }; const getDescription = (): void => { getModpackDescription(uuid, modpack.id).then((description) => setModpackDesc(description)); }; const openSite = (): void => { throw new Error('Function not implemented.'); }; return (

{modpack.summary}

setVisible(false)} modpack={modpack}>

{modpack.name}

{modpack.summary}

{modpack.screenshots.map((screenshot) => ( ))}
{modpack.downloadCount}
setInstallVisible(false)} modpack={modpack}>
{installing ? (

Installing...

) : ( modpack.latestFiles.map((file) => (

{file.displayName}

{file.gameVersions[0]}
)))}
); };