import { useEffect, useState } from "preact/hooks"; import { useNavigate } from "react-router-dom"; export function Home() { const [loading, setLoading] = useState(true); const [mcPath, setMcPath] = useState(""); const [worlds, setWorlds] = useState<{ world: string; icon: string; path: string; }[]>([]); const fetchWorlds = async () => { const res = await fetch("/api/dir"); const json = await res.json(); setMcPath(json.mcPath); setWorlds(json.worlds); setLoading(false); }; useEffect(() => { document.title = "BearMetal Packer"; fetchWorlds(); }, []); const submitMcPath = async (event: SubmitEvent) => { setLoading(true); event.preventDefault(); const form = new FormData(event.target as HTMLFormElement); const res = await fetch("/api/dir", { method: "POST", body: form, }); if (res.status === 200) { fetchWorlds(); } else setLoading(false); }; const nav = useNavigate(); const setWorld = async (worldPath: string) => { setLoading(true); const res = await fetch("/api/world", { method: "POST", body: worldPath, }); if (res.status === 200) { nav("/editor"); } else setLoading(false); }; return (

Welcome BearMetal Packer

An all in one toolkit to build datapacks for Minecraft.

{loading ?

Hold tight, we're doing some heavy lifting.

: ( <> {mcPath ? ( <>

Minecraft directory set to {mcPath}

Worlds:

) : ( <>

No Minecraft directory set, please set now:

)} )}
); }