import { useEffect, useState } from "react"; import { api, asUiError } from "@/lib/api"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { useT } from "@/i18n"; /** Takes a server out of the Manager's list. Nothing on disk is deleted, so the folder can be added again later. */ export function RemoveServerCard({ serverId, path, onForget }: { serverId: string; path: string; onForget: () => Promise }) { const t = useT(); const [running, setRunning] = useState(false); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); useEffect(() => { let active = true; void api.status(serverId).then((s) => { if (!active) return; const all = [s.observed.mysql, s.observed.auth, s.observed.world, ...(s.observed.secondary_world ? [s.observed.secondary_world] : []), ...(s.observed.reborn_world ? [s.observed.reborn_world] : [])]; setRunning(all.some((x) => x.state === "running" || x.state === "starting" || x.state === "stopping")); }).catch(() => { /* an unreadable status must not hide the button */ }); return () => { active = false; }; }, [serverId]); async function remove() { if (!window.confirm(t("remove.confirm", { path }))) return; setBusy(true); setError(null); try { await onForget(); } catch (e) { setError(asUiError(e).technical); setBusy(false); } } return

{t("remove.title")}

{t("remove.text")}

{path}

{running &&

{t("remove.stopFirst")}

} {error &&

{error}

}
; }