import { useEffect, useState } from "preact/hooks"; import type { FunctionComponent } from "preact"; import { Loader } from "./loader.tsx"; interface IProps { packName: string; } export const PackInfo: FunctionComponent = ({ packName }) => { const [showVersions, setShowVersions] = useState(false); const [packVersion, setPackVersion] = useState(""); const [packVersionList, setPackVersionList] = useState([]); const [loading, setLoading] = useState(true); const [world, setWorld] = useState(""); useEffect(() => { Promise.all([ fetch("/api/pack/version").then((res) => res.text()).then((text) => { setPackVersion(text); }), fetch("/api/versions").then((res) => res.json()).then((json) => { setPackVersionList(json); }), fetch("/api/world").then((res) => res.text()).then((text) => { setWorld(text); }), ]).finally(() => setLoading(false)); }, []); const updatePackVersion = async (version: string) => { const res = await fetch("/api/pack/version", { method: "POST", body: version, }); if (res.status === 200) { setPackVersion(version); } }; return ( <>

{world} :: {packName}

{loading ? : ( <> Datapack Version:{" "} setShowVersions(!showVersions)} > {packVersion} {showVersions && (

)} )}

); };