mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-19 03:25:56 +00:00
Fix settings input, client launch, server repair and simultaneous realms
This commit is contained in:
1 parent
162bfd1e04
commit
c02c635463
48 files changed
+1218
-72
No files matched your search
@@ -142,6 +142,7 @@ export function FriendsPage({ serverId }: { serverId: string }) {
|
||||
{t("fr.st.private")}
|
||||
</Line>
|
||||
</ul>
|
||||
{st.secondary_world_port && <p className="mt-3 text-sm text-muted">{t("realm.secondPort", { port: st.secondary_world_port })}</p>}
|
||||
</Card>
|
||||
|
||||
<div className="mt-6 grid gap-3">
|
||||
|
||||
@@ -195,8 +195,8 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
);
|
||||
}
|
||||
|
||||
const { mysql, auth, world } = status.observed;
|
||||
const all = [mysql, auth, world];
|
||||
const { mysql, auth, world, secondary_world } = status.observed;
|
||||
const all = [mysql, auth, world, ...(secondary_world ? [secondary_world] : [])];
|
||||
const running = all.every((s) => s.state === "running");
|
||||
const anyUp = all.some((s) => s.state !== "stopped");
|
||||
const transitioning = action !== null || status.busy || realmBusy;
|
||||
@@ -233,6 +233,7 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
<Row label={t("overview.database")} s={mysql} />
|
||||
<Row label={t("overview.auth")} s={auth} />
|
||||
<Row label={t("overview.world")} s={world} />
|
||||
{secondary_world && <Row label={t("realm.secondWorld")} s={secondary_world} />}
|
||||
</div>
|
||||
|
||||
<dl className="mt-4 grid grid-cols-2 gap-4 text-sm">
|
||||
@@ -323,9 +324,9 @@ export function Overview({ server, companions = true, onForget, onOpenUpdates, o
|
||||
{t("btn.updateClient")}
|
||||
</Button>
|
||||
) : client ? (
|
||||
<Button variant={running ? "primary" : "secondary"} size="xl" disabled={transitioning || playing} onClick={() => void play()} className="min-w-40">
|
||||
<Button variant="primary" size="xl" disabled={realmBusy || playing} onClick={() => void play()} className="min-w-40">
|
||||
{playing && <Loader2 className="h-5 w-5 animate-spin" aria-hidden />}
|
||||
{running ? t("btn.play") : t("btn.startPlay")}
|
||||
{t("btn.play")}
|
||||
</Button>
|
||||
) : client === null ? (
|
||||
<Button variant="secondary" size="xl" onClick={() => setDialog("setup")} className="min-w-40">
|
||||
|
||||
@@ -44,7 +44,7 @@ export function RealmPicker({ serverId, running, disabled, onChanged, onBusy }:
|
||||
</Button>}
|
||||
{view && <span className="ml-auto text-xs text-muted">{t("realm.active", { name: view.active === "coa" ? "CoA" : "Wildcard" })}</span>}
|
||||
</div>
|
||||
<p className="mt-3 text-sm text-muted">{t("realm.separate")}</p>
|
||||
<p className="mt-3 text-sm text-muted">{t(view?.simultaneous ? "realm.bothRunning" : "realm.separate")}</p>
|
||||
{selected === "wildcard" && <p className="mt-2 text-sm text-warn">{t("realm.modules")}</p>}
|
||||
{view && !view.supported && <p className="mt-2 text-sm text-warn">{t("realm.update")}</p>}
|
||||
{view?.recovery_pending && <p className="mt-2 text-sm text-warn">{t("realm.recovery")}</p>}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { api, asUiError, type RealmProfiles } from "@/lib/api";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useT } from "@/i18n";
|
||||
|
||||
export function RealmStartupSettings({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const [view, setView] = useState<RealmProfiles | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
void api.realmProfiles(serverId).then(v => { if (alive) setView(v); }).catch(e => { if (alive) setError(asUiError(e).technical); });
|
||||
return () => { alive = false; };
|
||||
}, [serverId]);
|
||||
async function change(enabled: boolean) {
|
||||
setBusy(true); setError(null);
|
||||
try { setView(await api.realmSimultaneous(serverId, enabled)); }
|
||||
catch (e) { setError(asUiError(e).technical); }
|
||||
finally { setBusy(false); }
|
||||
}
|
||||
return <Card className="mt-6 p-6" aria-busy={busy}>
|
||||
<h2 className="font-semibold">{t("realm.startupTitle")}</h2>
|
||||
<label className="mt-3 flex items-center gap-3">
|
||||
<input type="checkbox" checked={view?.simultaneous ?? false} disabled={!view || busy || !view.supported} onChange={e => void change(e.target.checked)} />
|
||||
<span>{t("realm.simultaneous")}</span>
|
||||
</label>
|
||||
<p className="mt-2 text-sm text-muted">{t("realm.simultaneousHint")}</p>
|
||||
{view?.simultaneous && <p className="mt-2 text-sm text-muted">{t("realm.secondPort", { port: view.secondary_world_port ?? "—" })}</p>}
|
||||
{busy && <p className="mt-2 text-sm" role="status">{t("realm.preparing")}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
|
||||
</Card>;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
import { useState } from "react";
|
||||
import { api, asUiError, type DatabaseCheck } from "@/lib/api";
|
||||
import { repairServer, useRepair, clearRepairResult } from "@/lib/repairJob";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useT } from "@/i18n";
|
||||
|
||||
export function RepairCard({ serverId }: { serverId: string }) {
|
||||
const t = useT();
|
||||
const job = useRepair(serverId);
|
||||
const [checking, setChecking] = useState(false);
|
||||
const [database, setDatabase] = useState<DatabaseCheck[] | null>(null);
|
||||
const [files, setFiles] = useState<{ path: string; kind: string }[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
async function check() {
|
||||
clearRepairResult(serverId);
|
||||
setChecking(true); setError(null); setDatabase(null); setFiles(null);
|
||||
try {
|
||||
setFiles(await api.verifyFiles(serverId));
|
||||
setDatabase(await api.checkDatabase(serverId));
|
||||
} catch (e) { setError(asUiError(e).technical); }
|
||||
finally { setChecking(false); }
|
||||
}
|
||||
const checks = job.result?.database ?? database;
|
||||
const busy = checking || job.busy;
|
||||
return <Card className="mt-6 p-6" aria-busy={busy}>
|
||||
<h2 className="font-semibold">{t("repair.title")}</h2>
|
||||
<p className="mt-2 text-sm text-muted">{t("repair.hint")}</p>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
<Button disabled={busy} onClick={() => void check()}>{checking ? t("repair.checking") : t("repair.check")}</Button>
|
||||
<Button disabled={busy} onClick={() => void repairServer(serverId)}>{job.busy ? t("repair.running", { n: job.percent }) : t("repair.run")}</Button>
|
||||
</div>
|
||||
{job.result && <div className="mt-3 text-sm" role="status">
|
||||
<p>{t("repair.result", { files: job.result.restored.length, sql: job.result.applied.length })}</p>
|
||||
<p className="selectable text-muted">{t("repair.backup", { id: job.result.backup })}</p>
|
||||
{job.result.error && <p className="mt-2 text-bad">{job.result.error}</p>}
|
||||
</div>}
|
||||
{files && !job.result && <p className="mt-3 text-sm">{t("repair.fileCount", { n: files.length })}</p>}
|
||||
{checks?.map(c => {
|
||||
const pending = c.migrations.filter(m => m.status !== "applied");
|
||||
return <div key={c.realm} className="mt-4 border-t border-line pt-3 text-sm">
|
||||
<p className="font-medium">{c.realm === "coa" ? "Conquest of Azeroth" : "Wildcard"}</p>
|
||||
<p className={c.problems.length || pending.length ? "text-warn" : "text-ok"}>{t("repair.dbCount", { columns: c.problems.length, sql: pending.length })}</p>
|
||||
{!c.full_schema && <p className="mt-1 text-muted">{t("repair.limited")}</p>}
|
||||
<ul className="mt-2 max-h-52 overflow-auto selectable text-muted">
|
||||
{c.problems.map((p,i) => <li key={i}>{p.database}.{p.table}{p.column ? `.${p.column}` : ""}: {p.detail}</li>)}
|
||||
{pending.map(m => <li key={m.db + m.id}>{m.db}/{m.id}: {m.status}{m.error ? ` — ${m.error}` : ""}</li>)}
|
||||
</ul>
|
||||
{c.problems.length > 0 && <p className="mt-2 text-warn">{t("repair.unresolved")}</p>}
|
||||
</div>;
|
||||
})}
|
||||
{(error || job.error) && <p className="mt-3 text-sm text-bad" role="alert">{job.error ?? error}</p>}
|
||||
</Card>;
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import { DiagnosticsCard } from "@/screens/DiagnosticsCard";
|
||||
import { AboutCard } from "@/screens/AboutCard";
|
||||
import { hasKey, useHuman, useI18n, type Key } from "@/i18n";
|
||||
import { LanguagePicker } from "@/components/LanguagePicker";
|
||||
import { RealmStartupSettings } from "@/screens/RealmStartupSettings";
|
||||
import { RepairCard } from "@/screens/RepairCard";
|
||||
|
||||
function mb(bytes: number) {
|
||||
return bytes >= 1 << 20 ? `${(bytes / (1 << 20)).toFixed(1)} MB` : `${Math.max(1, Math.round(bytes / 1024))} KB`;
|
||||
@@ -114,8 +116,10 @@ export function SettingsHome({ serverId }: { serverId: string }) {
|
||||
</Card>
|
||||
|
||||
<ClientCard serverId={serverId} />
|
||||
<RealmStartupSettings serverId={serverId} />
|
||||
|
||||
<DiagnosticsCard serverId={serverId} />
|
||||
<RepairCard key={serverId} serverId={serverId} />
|
||||
|
||||
<AboutCard />
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ function fmt(t: T, sx: SX, v: JsonValue, s: { key: string; type: string; unit?:
|
||||
|
||||
function clientCheck(t: T, s: SettingView, v: JsonValue): string | null {
|
||||
if (s.type === "int" || s.type === "float") {
|
||||
if (typeof v !== "number" || Number.isNaN(v)) return t("set.enterNumber");
|
||||
if (typeof v !== "number" || !Number.isFinite(v)) return t("set.enterNumber");
|
||||
if (s.type === "int" && !Number.isInteger(v)) return t("set.enterInt");
|
||||
if (s.min !== undefined && v < s.min) return t("set.atLeast", { n: s.min });
|
||||
if (s.max !== undefined && v > s.max) return t("set.atMost", { n: s.max });
|
||||
@@ -51,6 +51,8 @@ function Field(props: { s: SettingView; value: JsonValue; error: string | null;
|
||||
const { s, value, error, onChange } = props;
|
||||
const t = useT();
|
||||
const sx = useSchemaText();
|
||||
const [text, setText] = useState(String(value));
|
||||
useEffect(() => setText(String(value)), [value]);
|
||||
const id = `f-${s.key}`;
|
||||
const base = "rounded-md border bg-bg px-3 py-2 text-sm outline-none focus:border-gold";
|
||||
if (s.type === "bool") {
|
||||
@@ -89,12 +91,15 @@ function Field(props: { s: SettingView; value: JsonValue; error: string | null;
|
||||
<input
|
||||
id={id}
|
||||
className={cn(base, numeric ? "w-32 text-right" : "w-72", error ? "border-bad" : "border-line")}
|
||||
value={String(value)}
|
||||
value={text}
|
||||
inputMode={numeric ? "decimal" : undefined}
|
||||
aria-invalid={!!error}
|
||||
onChange={(e) => {
|
||||
const raw = e.target.value;
|
||||
onChange(numeric ? (raw.trim() === "" || Number.isNaN(Number(raw)) ? (raw as unknown as number) : Number(raw)) : raw);
|
||||
setText(raw);
|
||||
const normalized = raw.replace(",", ".");
|
||||
const number = Number(normalized);
|
||||
onChange(numeric && normalized.trim() !== "" && Number.isFinite(number) ? number : raw);
|
||||
}}
|
||||
/>
|
||||
{s.unit && <span className="text-xs text-muted">{sx.unit(s.unit)}</span>}
|
||||
|
||||
Reference in new issue
Block a user