Modules page: square icon cards with status (early/beta/release), switch, GitHub and settings; companions, scaling, TBC and WotLK packs and client compatibility in the catalog; a module switched off hides its page. Accounts: delete an account with confirmation.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-10-02 11:26:09 +05:00
1 parent 14173d7d7e
commit 726b089f42
16 files changed
+514 -53

No files matched your search

+31 -2
View File
@@ -9,7 +9,7 @@ import { useHuman, useT, type Key } from "@/i18n";
const LEVELS = [0, 1, 2, 3] as const;
const inputClass = "w-64 rounded-md border border-line bg-bg px-3 py-2 text-sm outline-none focus:border-gold";
type Editor = { name: string; mode: "password" | "rename" };
type Editor = { name: string; mode: "password" | "rename" | "delete"; characters?: number };
/** Everyone who can log in to the server, with the changes an owner usually needs: password, access level, name. */
export function AccountsCard({ serverId, online, reloadKey }: { serverId: string; online: boolean | null; reloadKey: number }) {
@@ -19,6 +19,7 @@ export function AccountsCard({ serverId, online, reloadKey }: { serverId: string
const [listError, setListError] = useState(false);
const [editor, setEditor] = useState<Editor | null>(null);
const [newName, setNewName] = useState("");
const [confirmName, setConfirmName] = useState("");
const [password, setPassword] = useState("");
const [busy, setBusy] = useState<string | null>(null);
const [error, setError] = useState<UiError | null>(null);
@@ -48,6 +49,7 @@ export function AccountsCard({ serverId, online, reloadKey }: { serverId: string
setEditor(null);
setPassword("");
setNewName("");
setConfirmName("");
await load();
} catch (e) {
setError(asUiError(e));
@@ -120,6 +122,9 @@ export function AccountsCard({ serverId, online, reloadKey }: { serverId: string
<Button size="sm" variant="ghost" disabled={!online || busy !== null || a.online} onClick={() => { setEditor({ name: a.name, mode: "rename" }); setError(null); setNote(null); }}>
{t("acc.rename")}
</Button>
<Button size="sm" variant="ghost" className="text-bad hover:text-bad" disabled={!online || busy !== null || a.online} onClick={() => { setEditor({ name: a.name, mode: "delete", characters: a.characters }); setConfirmName(""); setError(null); setNote(null); }}>
{t("acc.delete")}
</Button>
</td>
</tr>
))}
@@ -129,7 +134,31 @@ export function AccountsCard({ serverId, online, reloadKey }: { serverId: string
)}
{online === false && accounts && accounts.length > 0 && <p className="mt-3 text-xs text-muted">{t("acc.needsRunning")}</p>}
{editor && (
{editor && editor.mode === "delete" && (
<div className="mt-4 rounded-md border border-bad/40 bg-bad/5 p-4" role="alertdialog" aria-label={t("acc.deleteFor", { name: editor.name })}>
<p className="font-medium text-bad">{t("acc.deleteFor", { name: editor.name })}</p>
<p className="mt-2 text-sm">{t("acc.deleteWarn", { n: editor.characters ?? 0 })}</p>
<div className="mt-3">
<label htmlFor="acc-confirm" className="text-sm text-muted">{t("acc.deleteConfirm", { name: editor.name })}</label>
<input id="acc-confirm" className={inputClass + " mt-1 block"} value={confirmName} onChange={(e) => setConfirmName(e.target.value)} autoComplete="off" />
</div>
<div className="mt-4 flex gap-2">
<Button
variant="primary"
size="sm"
className="bg-bad text-white hover:bg-bad/90"
disabled={busy !== null || confirmName.trim().toUpperCase() !== editor.name.toUpperCase()}
onClick={() => void run("delete", () => api.accountDelete(serverId, editor.name), t("acc.deleted", { name: editor.name }))}
>
{busy === "delete" && <Loader2 className="h-4 w-4 animate-spin" aria-hidden />}
{t("acc.deleteButton")}
</Button>
<Button size="sm" variant="ghost" onClick={() => { setEditor(null); setConfirmName(""); }}>{t("common.cancel")}</Button>
</div>
</div>
)}
{editor && editor.mode !== "delete" && (
<div className="mt-4 rounded-md border border-line bg-black/20 p-4">
<p className="font-medium">{editor.mode === "password" ? t("acc.changeFor", { name: editor.name }) : t("acc.renameFor", { name: editor.name })}</p>
{editor.mode === "rename" && (
+108 -24
View File
@@ -1,13 +1,66 @@
import { useCallback, useEffect, useState } from "react";
import { ExternalLink, Loader2 } from "lucide-react";
import { useCallback, useEffect, useState, type ComponentType } from "react";
import { Bot, Flame, Loader2, Plug, Puzzle, Scaling, Settings2, Snowflake, type LucideProps } from "lucide-react";
import { api, asUiError, type ModuleSetting, type ModuleView, type UiError } from "@/lib/api";
import { cn } from "@/lib/utils";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
import { useHuman, useI18n } from "@/i18n";
import { useHuman, useI18n, type Key } from "@/i18n";
/** The server's optional modules: switch each on or off, open its page on GitHub, change its settings. */
export function ModulesPage({ serverId }: { serverId: string }) {
/** The GitHub mark (lucide dropped its brand icons). */
function GithubMark(props: { className?: string }) {
return (
<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden className={props.className}>
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 4 0c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z" />
</svg>
);
}
/** Icon and colours of a module's square tile, by the name the catalog gives it. */
const TILES: Record<string, { icon: ComponentType<LucideProps>; from: string; to: string }> = {
bot: { icon: Bot, from: "from-emerald-500", to: "to-teal-700" },
scaling: { icon: Scaling, from: "from-violet-500", to: "to-indigo-700" },
plug: { icon: Plug, from: "from-amber-500", to: "to-orange-700" },
tbc: { icon: Flame, from: "from-lime-500", to: "to-emerald-800" },
wotlk: { icon: Snowflake, from: "from-sky-400", to: "to-blue-700" },
};
const DEFAULT_TILE = { icon: Puzzle, from: "from-slate-500", to: "to-slate-700" };
const STATUS: Record<string, { label: Key; hint: Key; tone: string }> = {
early: { label: "mod.status.early", hint: "mod.hint.early", tone: "border-warn/50 bg-warn/10 text-warn" },
beta: { label: "mod.status.beta", hint: "mod.hint.beta", tone: "border-sky-400/50 bg-sky-400/10 text-sky-300" },
release: { label: "mod.status.release", hint: "mod.hint.release", tone: "border-ok/50 bg-ok/10 text-ok" },
};
function StatusBadge({ status }: { status: string }) {
const { t } = useI18n();
const s = STATUS[status] ?? STATUS.release;
return (
<span className={cn("shrink-0 rounded-full border px-2 py-0.5 text-[11px] font-medium uppercase tracking-wide", s.tone)} title={t(s.hint)}>
{t(s.label)}
</span>
);
}
function Tile({ icon, off }: { icon: string; off: boolean }) {
const tile = TILES[icon] ?? DEFAULT_TILE;
const Icon = tile.icon;
return (
<div
aria-hidden
className={cn(
"flex h-16 w-16 shrink-0 items-center justify-center rounded-2xl bg-gradient-to-br shadow-lg ring-1 ring-white/10 transition",
tile.from,
tile.to,
off && "opacity-40 grayscale",
)}
>
<Icon className="h-8 w-8 text-white drop-shadow" strokeWidth={1.75} />
</div>
);
}
/** The server's optional modules: square cards with a switch, the module's status, a link to GitHub and its settings. */
export function ModulesPage({ serverId, onChanged }: { serverId: string; onChanged?: () => void }) {
const { t, locale } = useI18n();
const human = useHuman();
const [modules, setModules] = useState<ModuleView[] | null>(null);
@@ -33,30 +86,47 @@ export function ModulesPage({ serverId }: { serverId: string }) {
await api.moduleSetEnabled(serverId, m.id, !m.enabled);
setChanged(true);
await load();
onChanged?.();
} catch (e) {
setError(asUiError(e));
}
}
const selected = modules?.find((m) => m.id === open) ?? null;
return (
<div className="max-w-3xl">
<div className="max-w-4xl">
<h1 className="text-2xl font-semibold">{t("mod.title")}</h1>
<p className="mt-1 text-muted">{t("q.modules")}</p>
<p className="mt-3 text-sm text-muted">{t("mod.intro")}</p>
{changed && <p className="mt-3 rounded-md border border-gold/40 bg-gold/5 px-3 py-2 text-sm" role="status">{t("mod.restart")}</p>}
<div className="mt-3 flex flex-wrap items-center gap-x-4 gap-y-2 text-xs text-muted" aria-label={t("mod.legend")}>
{(["early", "beta", "release"] as const).map((s) => (
<span key={s} className="flex items-center gap-2">
<StatusBadge status={s} />
{t(STATUS[s].hint)}
</span>
))}
</div>
{changed && <p className="mt-4 rounded-md border border-gold/40 bg-gold/5 px-3 py-2 text-sm" role="status">{t("mod.restart")}</p>}
{error && <p className="mt-3 text-sm text-bad" role="alert">{error.human.code === "unknown" ? error.technical : human(error.human).message}</p>}
<div className="mt-6 space-y-4">
<div className="mt-6 grid gap-4 sm:grid-cols-2">
{modules === null && !error && <p className="text-muted">{t("overview.checking")}</p>}
{modules?.length === 0 && <Card className="p-6 text-center text-muted">{t("mod.empty")}</Card>}
{modules?.length === 0 && <Card className="p-6 text-center text-muted sm:col-span-2">{t("mod.empty")}</Card>}
{modules?.map((m) => (
<Card key={m.id} className={cn("p-5", !m.installed && "opacity-60")}>
<div className="flex items-start justify-between gap-4">
<div className="min-w-0">
<h2 className="font-semibold">{m.name}</h2>
<p className="mt-1 text-sm text-muted">{m.description[locale] ?? m.description.en}</p>
<Card key={m.id} className={cn("flex flex-col gap-4 p-5 transition-colors", !m.installed && "opacity-60", open === m.id && "border-gold/50")}>
<div className="flex items-start gap-4">
<Tile icon={m.icon} off={!m.enabled || !m.installed} />
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
<h2 className="font-semibold leading-tight">{m.name}</h2>
<StatusBadge status={m.status} />
</div>
<p className="mt-1.5 line-clamp-2 text-sm text-muted">{m.description[locale] ?? m.description.en}</p>
</div>
{m.installed ? (
{m.installed && m.switchable && (
<button
role="switch"
aria-checked={m.enabled}
@@ -66,24 +136,35 @@ export function ModulesPage({ serverId }: { serverId: string }) {
>
<span className={cn("absolute top-0.5 h-5 w-5 rounded-full bg-white transition-all", m.enabled ? "left-[22px]" : "left-0.5")} />
</button>
) : (
<span className="mt-1 shrink-0 text-xs text-muted">{t("mod.notHere")}</span>
)}
{m.installed && !m.switchable && <span className="mt-1.5 shrink-0 text-xs text-muted">{t("mod.alwaysOn")}</span>}
{!m.installed && <span className="mt-1.5 shrink-0 text-xs text-muted">{t("mod.notHere")}</span>}
</div>
<div className="mt-3 flex flex-wrap gap-2">
<Button size="sm" variant="ghost" onClick={() => void api.openLink(m.repo)}>
<ExternalLink className="h-3.5 w-3.5" aria-hidden /> {t("mod.github")}
</Button>
<div className="mt-auto flex items-center gap-2">
<button
onClick={() => void api.openLink(m.repo)}
title={t("mod.github")}
aria-label={`${t("mod.github")}: ${m.name}`}
className="flex h-8 w-8 cursor-pointer items-center justify-center rounded-md border border-line text-muted transition-colors hover:border-gold/50 hover:text-ink"
>
<GithubMark className="h-4 w-4" />
</button>
{m.installed && (
<Button size="sm" variant="ghost" aria-expanded={open === m.id} onClick={() => setOpen(open === m.id ? null : m.id)}>
{t("mod.settings")}
<Settings2 className="h-3.5 w-3.5" aria-hidden /> {t("mod.settings")}
</Button>
)}
</div>
{open === m.id && <ModuleSettings serverId={serverId} module={m} onSaved={() => setChanged(true)} />}
</Card>
))}
</div>
{selected && (
<Card className="mt-4 p-5">
<h2 className="font-semibold">{t("mod.settingsOf", { name: selected.name })}</h2>
<ModuleSettings serverId={serverId} module={selected} onSaved={() => setChanged(true)} />
</Card>
)}
</div>
);
}
@@ -98,6 +179,9 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
const [note, setNote] = useState<string | null>(null);
useEffect(() => {
setItems(null);
setEdits({});
setNote(null);
void api.moduleSettings(serverId, module.id).then((s) => setItems(s)).catch((e) => setError(asUiError(e)));
}, [serverId, module.id]);
@@ -122,7 +206,7 @@ function ModuleSettings({ serverId, module, onSaved }: { serverId: string; modul
const dirty = Object.keys(edits).length > 0;
return (
<div className="mt-4 border-t border-line pt-4">
<div className="mt-3 border-t border-line pt-3">
{items === null && !error && <Loader2 className="h-4 w-4 animate-spin text-muted" aria-hidden />}
<ul className="divide-y divide-line">
{items?.map((s) => (
+3 -3
View File
@@ -62,7 +62,7 @@ function Row({ label, s }: { label: string; s: ServiceStatus }) {
);
}
export function Overview({ server, onForget, onOpenUpdates }: { server: ServerSummary; onForget: () => Promise<void>; onOpenUpdates: () => void }) {
export function Overview({ server, companions = true, onForget, onOpenUpdates }: { server: ServerSummary; /** the companions module is on */ companions?: boolean; onForget: () => Promise<void>; onOpenUpdates: () => void }) {
const t = useT();
const human = useHuman();
const [status, setStatus] = useState<StatusView | null>(null);
@@ -230,10 +230,10 @@ export function Overview({ server, onForget, onOpenUpdates }: { server: ServerSu
</div>
<div>
<dt className="text-muted">{t("overview.players")}</dt>
<dd className="mt-0.5 text-lg">{pop ? `${pop.players_online}` : "—"}{pop && pop.bots_online > 0 ? <span className="ml-2 text-sm text-muted">{t("overview.companions", { n: pop.bots_online })}</span> : null}</dd>
<dd className="mt-0.5 text-lg">{pop ? `${pop.players_online}` : "—"}{companions && pop && pop.bots_online > 0 ? <span className="ml-2 text-sm text-muted">{t("overview.companions", { n: pop.bots_online })}</span> : null}</dd>
</div>
</dl>
{startBots !== undefined && (
{companions && startBots !== undefined && (
<p className="mt-3 text-xs text-muted">{startBots === null ? t("overview.startBotsOff") : t("overview.startBots", { n: startBots })}</p>
)}
{perf && <TickRate perf={perf} />}
+20 -5
View File
@@ -1,6 +1,6 @@
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { Archive, Bot, Bug, Gauge, Globe, Puzzle, Server, Settings, Terminal, Users, type LucideIcon } from "lucide-react";
import { type ServerSummary } from "@/lib/api";
import { api, type ServerSummary } from "@/lib/api";
import { useT, type Key } from "@/i18n";
import logo from "@/assets/logo.png";
import { cn } from "@/lib/utils";
@@ -46,6 +46,21 @@ export function Shell(props: {
const current = NAV.find((n) => n.id === page)!;
const update = useServerUpdate(props.activeId);
// A module that is switched off takes its page away (the companions' "Bots" page, for one).
const [hiddenPages, setHiddenPages] = useState<string[]>([]);
const reloadModules = useCallback(() => {
void api
.modulesList(props.activeId)
.then((list) => setHiddenPages(list.filter((m) => m.page && m.installed && m.switchable && !m.enabled).map((m) => m.page as string)))
.catch(() => setHiddenPages([]));
}, [props.activeId]);
useEffect(() => {
reloadModules();
}, [reloadModules]);
useEffect(() => {
if (hiddenPages.includes(page)) setPage("overview");
}, [hiddenPages, page]);
// Look for a server and a game client update when the app starts and then every five minutes.
useEffect(() => {
const stopServer = startServerUpdatePolling(props.activeId);
@@ -64,7 +79,7 @@ export function Shell(props: {
{t("app.name")}
</div>
<ul className="flex flex-col gap-0.5">
{NAV.map(({ id, label, icon: Icon }) => (
{NAV.filter((n) => !hiddenPages.includes(n.id)).map(({ id, label, icon: Icon }) => (
<li key={id}>
<button
onClick={() => setPage(id)}
@@ -107,13 +122,13 @@ export function Shell(props: {
<main className="h-full flex-1 overflow-y-auto px-10 py-8">
{page === "overview" ? (
<Overview key={server.id} server={server} onForget={() => props.onForget(server.id)} onOpenUpdates={() => setPage("settings")} />
<Overview key={server.id} server={server} companions={!hiddenPages.includes("bots")} onForget={() => props.onForget(server.id)} onOpenUpdates={() => setPage("settings")} />
) : page === "bots" || page === "server" ? (
<SettingsPage key={`${server.id}-${page}`} serverId={server.id} scope={page} title={t(current.label)} question={t(current.question)} />
) : page === "console" ? (
<ConsolePage key={server.id} serverId={server.id} />
) : page === "modules" ? (
<ModulesPage key={server.id} serverId={server.id} />
<ModulesPage key={server.id} serverId={server.id} onChanged={reloadModules} />
) : page === "report" ? (
<ReportPage key={server.id} serverId={server.id} />
) : page === "friends" ? (