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"; import { useAtom } from "jotai"; import { namespaceAtom } from "../atoms/namespace.ts"; import { Outlet, Route, Routes } from "react-router-dom"; import { Selector } from "../components/editor/selector.tsx"; import { NamespaceModal } from "../components/editor/namespaceModal.tsx"; import { EditorWrapper } from "../components/editor/wrapper.tsx"; import { TagRouter } from "../components/editor/tags/editor.tsx"; export const Editor = () => { const [packName, setPackName] = useState(""); const [loading, setLoading] = useState(true); const [namespaces, setNamespaces] = useState([]); const [namespace, setNamespace] = useAtom(namespaceAtom); const fetchNamespaces = async () => { const res = await fetch("/api/pack/namespaces"); const json = await res.json(); setNamespaces(json); }; useEffect(() => { document.title = "BearMetal Packer"; fetch("/api/pack").then((res) => res.json()).then((json) => { setPackName(json.packName); setLoading(false); }); fetchNamespaces(); }, []); const setPackNameThing = async (event: SubmitEvent) => { setLoading(true); const res = await fetch("/api/pack", { method: "POST", body: new FormData(event.target as HTMLFormElement), }); if (res.status === 200) { document.title = packName; setPackName(packName); } setLoading(false); }; if (!packName) { return ( {loading ?

Just a sec, trying to put the cats back in the bag.

: ( <>
OR )}
); } const [showNamespaceModal, setShowNamespaceModal] = useState(false); return (

BearMetalPacker

Namespaces
    {namespaces.map((namespace) => (
  • setNamespace(namespace)} > {namespace}
  • ))}
{showNamespaceModal && ( { setShowNamespaceModal(false); fetchNamespaces(); }} /> )}
{!namespace ?
No namespace set
: ( <>

Namespace: {namespace}

} /> } > } /> )}
); };