mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-25 19:25:56 +00:00
UI: translate Diagnostics and About cards
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
488a1a45c6
commit
0b975a7c42
8 files changed
+168
-23
No files matched your search
@@ -5,8 +5,10 @@ import { relaunch } from "@tauri-apps/plugin-process";
|
||||
import { Loader2 } from "lucide-react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useT } from "@/i18n";
|
||||
|
||||
export function AboutCard() {
|
||||
const t = useT();
|
||||
const [version, setVersion] = useState("");
|
||||
const [update, setUpdate] = useState<Update | null>(null);
|
||||
const [busy, setBusy] = useState<"check" | "install" | null>(null);
|
||||
@@ -25,9 +27,9 @@ export function AboutCard() {
|
||||
try {
|
||||
const u = await check();
|
||||
setUpdate(u);
|
||||
if (!u) setNote("CoA Server Manager is up to date.");
|
||||
if (!u) setNote(t("about.upToDate"));
|
||||
} catch {
|
||||
setError("Could not check for a new version. Check your internet connection and try again.");
|
||||
setError(t("about.checkFailed"));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
@@ -49,24 +51,24 @@ export function AboutCard() {
|
||||
});
|
||||
await relaunch();
|
||||
} catch {
|
||||
setError("The update could not be installed. Your server was not touched.");
|
||||
setError(t("about.installFailed"));
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">CoA Server Manager</h2>
|
||||
<p className="mt-1 text-sm text-muted">Version {version || "…"}. Updates to the program never change your server.</p>
|
||||
<h2 className="font-semibold">{t("app.name")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("about.version", { v: version || "…" })}</p>
|
||||
<div className="mt-4 flex items-center gap-3">
|
||||
<Button size="sm" disabled={!!busy} onClick={() => void look()}>
|
||||
{busy === "check" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
Check for a new version
|
||||
{t("about.check")}
|
||||
</Button>
|
||||
{update && (
|
||||
<Button size="sm" variant="primary" disabled={!!busy} onClick={() => void install()}>
|
||||
{busy === "install" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
Install {update.version} and restart
|
||||
{t("about.install", { v: update.version })}
|
||||
</Button>
|
||||
)}
|
||||
{percent !== null && busy === "install" && <span className="text-sm text-muted" role="status">{percent}%</span>}
|
||||
|
||||
@@ -3,12 +3,15 @@ import { Check, Loader2, TriangleAlert, X } from "lucide-react";
|
||||
import { api, asUiError, type DiagCheck, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useI18n } from "@/i18n";
|
||||
|
||||
const ICON = { ok: Check, warn: TriangleAlert, fail: X } as const;
|
||||
const TONE = { ok: "text-ok", warn: "text-warn", fail: "text-bad" } as const;
|
||||
const WORD = { ok: "OK", warn: "Attention", fail: "Problem" } as const;
|
||||
const WORD = { ok: "diag.word.ok", warn: "diag.word.warn", fail: "diag.word.fail" } as const;
|
||||
|
||||
export function DiagnosticsCard({ serverId }: { serverId: string }) {
|
||||
const { t, tn } = useI18n();
|
||||
const human = useHuman();
|
||||
const [checks, setChecks] = useState<DiagCheck[] | null>(null);
|
||||
const [files, setFiles] = useState<{ path: string; kind: string }[] | null>(null);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
@@ -32,24 +35,24 @@ export function DiagnosticsCard({ serverId }: { serverId: string }) {
|
||||
|
||||
return (
|
||||
<Card className="mt-6 p-6">
|
||||
<h2 className="font-semibold">Diagnostics</h2>
|
||||
<p className="mt-1 text-sm text-muted">Looks for common problems. Nothing is changed.</p>
|
||||
<h2 className="font-semibold">{t("diag.title")}</h2>
|
||||
<p className="mt-1 text-sm text-muted">{t("diag.text")}</p>
|
||||
<div className="mt-4 flex flex-wrap gap-2">
|
||||
<Button variant="primary" disabled={!!busy} onClick={() => void run("diag", async () => setChecks((await api.runDiagnostics(serverId)).checks))}>
|
||||
{busy === "diag" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
|
||||
Run diagnostics
|
||||
{t("diag.run")}
|
||||
</Button>
|
||||
<Button disabled={!!busy} onClick={() => void run("verify", async () => setFiles(await api.verifyFiles(serverId)))}>
|
||||
Check server files
|
||||
{t("diag.verify")}
|
||||
</Button>
|
||||
<Button variant="ghost" disabled={!!busy} onClick={() => void run("export", async () => setNote(`Saved for bug reports: ${await api.exportDiagnostics(serverId)}`))}>
|
||||
Export diagnostic package
|
||||
<Button variant="ghost" disabled={!!busy} onClick={() => void run("export", async () => setNote(t("diag.saved", { path: await api.exportDiagnostics(serverId) })))}>
|
||||
{t("diag.export")}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{checks && (
|
||||
<div className="mt-4">
|
||||
<p className="font-medium" role="status">{problems === 0 ? "Everything looks good." : `${problems} thing${problems === 1 ? "" : "s"} to look at`}</p>
|
||||
<p className="font-medium" role="status">{problems === 0 ? t("diag.allGood") : tn("diag.problems", problems)}</p>
|
||||
<ul className="mt-2 divide-y divide-line text-sm">
|
||||
{checks.map((c) => {
|
||||
const Icon = ICON[c.level];
|
||||
@@ -58,7 +61,7 @@ export function DiagnosticsCard({ serverId }: { serverId: string }) {
|
||||
<Icon className={`mt-0.5 h-4 w-4 shrink-0 ${TONE[c.level]}`} aria-hidden />
|
||||
<div>
|
||||
<span className="font-medium">{c.title}</span>
|
||||
<span className="sr-only"> — {WORD[c.level]}</span>
|
||||
<span className="sr-only"> — {t(WORD[c.level])}</span>
|
||||
<p className="text-muted">{c.detail}</p>
|
||||
</div>
|
||||
</li>
|
||||
@@ -71,14 +74,14 @@ export function DiagnosticsCard({ serverId }: { serverId: string }) {
|
||||
{files && (
|
||||
<div className="mt-4 border-t border-line pt-3 text-sm">
|
||||
{files.length === 0 ? (
|
||||
<p className="text-ok" role="status">All program files are intact.</p>
|
||||
<p className="text-ok" role="status">{t("diag.filesOk")}</p>
|
||||
) : (
|
||||
<>
|
||||
<p className="text-warn">{files.length} program file(s) differ from what was installed. Your own files are never listed here. "Check for updates" restores missing ones.</p>
|
||||
<p className="text-warn">{t("diag.filesDiffer", { n: files.length })}</p>
|
||||
<ul className="mt-2 max-h-40 overflow-auto">
|
||||
{files.map((f) => (
|
||||
<li key={f.path} className="selectable py-0.5">
|
||||
{f.path} <span className="text-muted">— {f.kind === "missing" ? "missing" : "changed"}</span>
|
||||
{f.path} <span className="text-muted">— {f.kind === "missing" ? t("diag.fileMissing") : t("diag.fileChanged")}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
@@ -87,7 +90,7 @@ export function DiagnosticsCard({ serverId }: { serverId: string }) {
|
||||
</div>
|
||||
)}
|
||||
{note && <p className="mt-3 text-sm text-ok" role="status">{note}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error.human.code === "unknown" ? error.technical : error.human.message}</p>}
|
||||
{error && <p className="mt-3 text-sm text-bad" role="alert">{error.human.code === "unknown" ? error.technical : human(error.human).message}</p>}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user