mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-25 11:25:56 +00:00
UI: translate Import and Install screens
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0a9be3d800
commit
9dee0ce8b1
7 files changed
+305
-56
No files matched your search
@@ -5,10 +5,23 @@ import { Check, ChevronDown, ChevronRight, Loader2 } from "lucide-react";
|
||||
import { api, asUiError, type InstallStep, type Preflight, type ServerSummary, type UiError } from "@/lib/api";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card } from "@/components/ui/card";
|
||||
import { useHuman, useT, type Key } from "@/i18n";
|
||||
|
||||
// The backend reports progress with these English step names; map the known ones to translations.
|
||||
const STEP_KEYS: Record<string, Key> = {
|
||||
"Preparing your server": "install.progressTitle",
|
||||
"Checking your computer": "install.step.checking",
|
||||
"Downloading server": "install.step.downloading",
|
||||
Unpacking: "install.step.unpacking",
|
||||
"Preparing database": "install.step.database",
|
||||
Finishing: "install.step.finishing",
|
||||
};
|
||||
|
||||
type Phase = "choose" | "installing" | "done";
|
||||
|
||||
export function InstallServer(props: { canCancel: boolean; onCancel: () => void; onDone: (s: ServerSummary) => void | Promise<void> }) {
|
||||
const t = useT();
|
||||
const human = useHuman();
|
||||
const [dest, setDest] = useState("C:\\Games\\CoA Server");
|
||||
const [pre, setPre] = useState<Preflight | null>(null);
|
||||
const [phase, setPhase] = useState<Phase>("choose");
|
||||
@@ -32,12 +45,12 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
}, []);
|
||||
|
||||
async function browse() {
|
||||
const picked = await open({ directory: true, multiple: false, title: "Choose where to install your server" });
|
||||
const picked = await open({ directory: true, multiple: false, title: t("install.dialogTitle") });
|
||||
if (typeof picked === "string") setDest(picked.replace(/[\\/]+$/, "") + (picked.toLowerCase().includes("coa") ? "" : "\\CoA Server"));
|
||||
}
|
||||
|
||||
async function browsePackage() {
|
||||
const picked = await open({ directory: true, multiple: false, title: "Choose a server package folder" });
|
||||
const picked = await open({ directory: true, multiple: false, title: t("install.pkgDialogTitle") });
|
||||
if (typeof picked === "string") setPkg(picked);
|
||||
}
|
||||
|
||||
@@ -58,12 +71,12 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
if (phase === "installing") {
|
||||
return (
|
||||
<main className="mx-auto flex h-full max-w-xl flex-col justify-center px-8">
|
||||
<h1 className="text-2xl font-semibold">Preparing your server</h1>
|
||||
<p className="mt-1 text-muted">This can take a few minutes. You can leave this window open.</p>
|
||||
<h1 className="text-2xl font-semibold">{t("install.progressTitle")}</h1>
|
||||
<p className="mt-1 text-muted">{t("install.progressText")}</p>
|
||||
<Card className="mt-8 p-6">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="flex items-center gap-2 font-medium">
|
||||
<Loader2 className="h-4 w-4 animate-spin text-gold" aria-hidden /> {step.step}
|
||||
<Loader2 className="h-4 w-4 animate-spin text-gold" aria-hidden /> {STEP_KEYS[step.step] ? t(STEP_KEYS[step.step]) : step.step}
|
||||
</span>
|
||||
<span className="text-sm text-muted" role="status">{step.percent}%</span>
|
||||
</div>
|
||||
@@ -74,7 +87,7 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
</Card>
|
||||
{step.step === "Downloading server" && (
|
||||
<Button className="mt-4 self-start" variant="ghost" size="sm" onClick={() => void api.cancelInstall()}>
|
||||
Cancel
|
||||
{t("common.cancel")}
|
||||
</Button>
|
||||
)}
|
||||
</main>
|
||||
@@ -87,10 +100,10 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
<div className="flex h-14 w-14 items-center justify-center rounded-full bg-ok/15">
|
||||
<Check className="h-7 w-7 text-ok" aria-hidden />
|
||||
</div>
|
||||
<h1 className="mt-5 text-2xl font-semibold">Your server is ready</h1>
|
||||
<p className="mt-1 text-muted">Everything is installed. Start it from the next screen.</p>
|
||||
<h1 className="mt-5 text-2xl font-semibold">{t("install.doneTitle")}</h1>
|
||||
<p className="mt-1 text-muted">{t("install.doneText")}</p>
|
||||
<Button className="mt-8" variant="primary" size="xl" onClick={() => void props.onDone(installed)}>
|
||||
OPEN MY SERVER
|
||||
{t("install.open")}
|
||||
</Button>
|
||||
</main>
|
||||
);
|
||||
@@ -99,12 +112,12 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
return (
|
||||
<main className="mx-auto flex h-full max-w-2xl flex-col justify-center gap-5 px-8 py-10">
|
||||
<div>
|
||||
<h1 className="text-2xl font-semibold">Install a new server</h1>
|
||||
<p className="mt-1 text-muted">Choose a folder, or keep the suggested one. Everything else is set up for you.</p>
|
||||
<h1 className="text-2xl font-semibold">{t("install.title")}</h1>
|
||||
<p className="mt-1 text-muted">{t("install.subtitle")}</p>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label htmlFor="dest" className="text-sm text-muted">Install to</label>
|
||||
<label htmlFor="dest" className="text-sm text-muted">{t("install.installTo")}</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<input
|
||||
id="dest"
|
||||
@@ -112,7 +125,7 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
onChange={(e) => setDest(e.target.value)}
|
||||
className="selectable flex-1 rounded-md border border-line bg-card px-3 py-2.5 text-[15px] outline-none focus:border-gold"
|
||||
/>
|
||||
<Button onClick={browse}>Browse…</Button>
|
||||
<Button onClick={browse}>{t("install.browse")}</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -123,15 +136,15 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
))}
|
||||
</Card>
|
||||
)}
|
||||
{pre?.ok && <p className="text-sm text-ok">This folder is ready. {Math.round(pre.free_bytes / (1 << 30))} GB free.</p>}
|
||||
{pre?.ok && <p className="text-sm text-ok">{t("install.ready", { gb: Math.round(pre.free_bytes / (1 << 30)) })}</p>}
|
||||
|
||||
{error && (
|
||||
<Card className="border-bad/40 p-4" role="alert">
|
||||
<p className="font-medium text-bad">{error.human.code === "unknown" ? "The installation could not finish" : error.human.title}</p>
|
||||
<p className="mt-1 text-sm text-muted">{error.human.code === "unknown" ? error.technical : error.human.message}</p>
|
||||
<p className="mt-1 text-sm text-muted">Nothing was installed. You can try again; downloaded files are kept.</p>
|
||||
<p className="font-medium text-bad">{error.human.code === "unknown" ? t("install.failedTitle") : human(error.human).title}</p>
|
||||
<p className="mt-1 text-sm text-muted">{error.human.code === "unknown" ? error.technical : human(error.human).message}</p>
|
||||
<p className="mt-1 text-sm text-muted">{t("install.nothingInstalled")}</p>
|
||||
<button className="mt-2 cursor-pointer text-xs text-muted underline" onClick={() => setShowDetails((v) => !v)}>
|
||||
{showDetails ? "Hide" : "Show"} technical details
|
||||
{showDetails ? t("install.hideTech") : t("install.showTech")}
|
||||
</button>
|
||||
{showDetails && <pre className="mt-2 max-h-40 overflow-auto whitespace-pre-wrap rounded bg-black/40 p-2 text-xs">{error.technical}</pre>}
|
||||
</Card>
|
||||
@@ -140,14 +153,14 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
<div>
|
||||
<button onClick={() => setShowAdvanced((v) => !v)} aria-expanded={showAdvanced} className="flex cursor-pointer items-center gap-1 text-sm text-muted hover:text-ink">
|
||||
{showAdvanced ? <ChevronDown className="h-4 w-4" aria-hidden /> : <ChevronRight className="h-4 w-4" aria-hidden />}
|
||||
Advanced
|
||||
{t("install.advanced")}
|
||||
</button>
|
||||
{showAdvanced && (
|
||||
<div className="mt-2">
|
||||
<label htmlFor="pkg" className="text-sm text-muted">Install from a local package folder instead of downloading</label>
|
||||
<label htmlFor="pkg" className="text-sm text-muted">{t("install.localPkg")}</label>
|
||||
<div className="mt-1 flex gap-2">
|
||||
<input id="pkg" value={pkg} onChange={(e) => setPkg(e.target.value)} placeholder="(leave empty to download)" className="selectable flex-1 rounded-md border border-line bg-card px-3 py-2 text-sm outline-none focus:border-gold" />
|
||||
<Button size="sm" onClick={browsePackage}>Browse…</Button>
|
||||
<input id="pkg" value={pkg} onChange={(e) => setPkg(e.target.value)} placeholder={t("install.localPkgHint")} className="selectable flex-1 rounded-md border border-line bg-card px-3 py-2 text-sm outline-none focus:border-gold" />
|
||||
<Button size="sm" onClick={browsePackage}>{t("install.browse")}</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
@@ -155,11 +168,11 @@ export function InstallServer(props: { canCancel: boolean; onCancel: () => void;
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
<Button variant="primary" size="md" disabled={!pre?.ok} onClick={() => void install()}>
|
||||
Install
|
||||
{t("install.button")}
|
||||
</Button>
|
||||
{props.canCancel && (
|
||||
<Button variant="ghost" onClick={props.onCancel}>
|
||||
Cancel
|
||||
{t("common.cancel")}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user