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 Spinner from '@/components/elements/Spinner'; import installModpack from '@/api/server/modpacks/installModpack'; import getFileExists from '@/api/server/files/getFileExists'; interface Props { modpack: Modpack; } interface ModpackManifest { author: string; files: ModpackFile[] manifestType: string; manifestVersion: number; minecraft: {}; name: string; overrides: string; version: string; } interface ModpackFile { projectID: number; fileID: number; required: boolean; } const timer = (ms: number) => new Promise(res => setTimeout(res, ms)) 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 [installed, setInstalled] = 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); await installModpack(uuid, modpack.id, latestFile.id); let uninstallableExists = false; while (!uninstallableExists) { uninstallableExists = await getFileExists(uuid, 'uninstallable.txt') as unknown as boolean; await timer(6500); } setInstalling(false); setInstalled(true); }; 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... This can take a while, sit back, grab a drink and relax

) : (<>{installed ? (

Modpack insatlled, if any mods couldn't be manually installed you can find them in the file 'uninstallable.txt', install them manually before playing.

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

{file.displayName}

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