diff --git a/deno.json b/deno.json index 504974d..ffb64d9 100644 --- a/deno.json +++ b/deno.json @@ -22,6 +22,7 @@ "@std/path": "jsr:@std/path@^1.0.6", "autoprefixer": "npm:autoprefixer@^10.4.20", "babel-plugin-transform-hook-names": "npm:babel-plugin-transform-hook-names@^1.0.2", + "jotai": "npm:jotai@^2.10.1", "less": "npm:less@^4.2.0", "postcss": "npm:postcss@^8.4.47", "preact": "npm:preact@^10.24.3", diff --git a/deno.lock b/deno.lock index 2104d42..7fc0c07 100644 --- a/deno.lock +++ b/deno.lock @@ -18,6 +18,7 @@ "npm:@types/node@*": "22.5.4", "npm:autoprefixer@^10.4.20": "10.4.20_postcss@8.4.47", "npm:babel-plugin-transform-hook-names@^1.0.2": "1.0.2_@babel+core@7.25.8", + "npm:jotai@^2.10.1": "2.10.1", "npm:less@^4.2.0": "4.2.0", "npm:postcss@^8.4.47": "8.4.47", "npm:preact@^10.24.3": "10.24.3", @@ -883,6 +884,9 @@ "jiti@1.21.6": { "integrity": "sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w==" }, + "jotai@2.10.1": { + "integrity": "sha512-4FycO+BOTl2auLyF2Chvi6KTDqdsdDDtpaL/WHQMs8f3KS1E3loiUShQzAzFA/sMU5cJ0hz/RT1xum9YbG/zaA==" + }, "js-tokens@4.0.0": { "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, @@ -1400,6 +1404,7 @@ "npm:@preact/preset-vite@^2.9.1", "npm:autoprefixer@^10.4.20", "npm:babel-plugin-transform-hook-names@^1.0.2", + "npm:jotai@^2.10.1", "npm:less@^4.2.0", "npm:postcss@^8.4.47", "npm:preact@^10.24.3", diff --git a/server/main.ts b/server/main.ts index f5339f2..5d19ec5 100644 --- a/server/main.ts +++ b/server/main.ts @@ -98,7 +98,7 @@ router.route("/api/world") using store = new BearMetalStore(); const worldPath = store.get("world") as string; if (!worldPath) return new Response(null, { status: 400 }); - return serveFile(req, worldPath); + return new Response(worldPath.split("/").pop() as string, { status: 200 }); }); router.route("/api/pack") diff --git a/src/classes.ts b/src/classes.ts new file mode 100644 index 0000000..de25add --- /dev/null +++ b/src/classes.ts @@ -0,0 +1,3 @@ +export const classList = (...classes: (string | undefined)[]) => { + return classes.filter(Boolean).join(" "); +}; diff --git a/src/components/loader.tsx b/src/components/loader.tsx index ade0d1f..d2cf620 100644 --- a/src/components/loader.tsx +++ b/src/components/loader.tsx @@ -1,8 +1,17 @@ -export const Loader = ({ msg }: { msg?: string }) => { +import { classList } from "../classes.ts"; + +interface IProps { + msg?: string; + class?: string; +} + +export const Loader = ({ msg, class: className }: IProps) => { return ( -
+
{!!msg &&

{msg}

} -
+
); diff --git a/src/components/packInfo.tsx b/src/components/packInfo.tsx new file mode 100644 index 0000000..a1eae69 --- /dev/null +++ b/src/components/packInfo.tsx @@ -0,0 +1,68 @@ +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 && ( +

    + {packVersionList.map((version) => ( +
  • updatePackVersion(version)}> + {version} +
  • + ))} +
+ )} + + + )} +

+ + ); +}; diff --git a/src/views/editor.tsx b/src/views/editor.tsx index 9f1af21..e1dae76 100644 --- a/src/views/editor.tsx +++ b/src/views/editor.tsx @@ -2,13 +2,12 @@ import { useEffect, useState } from "preact/hooks"; import { Modal } from "../components/modal.tsx"; import { LabelledHr } from "../components/labelledHr.tsx"; import { PacksList } from "../components/packsList.tsx"; +import { PackInfo } from "../components/packInfo.tsx"; export const Editor = () => { const [packName, setPackName] = useState(""); const [loading, setLoading] = useState(true); const [namespaces, setNamespaces] = useState([]); - const [packVersion, setPackVersion] = useState(""); - const [packVersionList, setPackVersionList] = useState([]); useEffect(() => { document.title = "BearMetal Packer"; @@ -16,12 +15,6 @@ export const Editor = () => { setPackName(json.packName); setLoading(false); }); - fetch("/api/pack/version").then((res) => res.text()).then((text) => { - setPackVersion(text); - }); - fetch("/api/versions").then((res) => res.json()).then((json) => { - setPackVersionList(json); - }); }, []); const setPackNameThing = async (event: SubmitEvent) => { @@ -63,43 +56,12 @@ export const Editor = () => { ); } - const [showVersions, setShowVersions] = useState(false); - - const updatePackVersion = async (version: string) => { - const res = await fetch("/api/pack/version", { - method: "POST", - body: version, - }); - - if (res.status === 200) { - setPackVersion(version); - } - }; - return (

BearMetalPacker

-

{packName}

-

- Datapack Version:{" "} - setShowVersions(!showVersions)} - > - {packVersion} - {showVersions && ( -

    - {packVersionList.map((version) => ( -
  • updatePackVersion(version)}> - {version} -
  • - ))} -
- )} - -

+
Namespaces