Phase 11: public realm list and detail, Player Mode server browser

Registry: GET /registry/v2/realms (keyset cursors, bounded filters and sorts, indexes per sort,
ETag and a short server-side cache, per-address limit) and /realms/{id}; migrations 3 and 4.
Manager: Servers page (table, filters, sortable columns, detail drawer, module tooltips from the
local catalog, players and bots apart, ping unknown), compatibility of the chosen character with
an advertised realm through the Phase 7/8 rules.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ДмитрийandClaude Sonnet 5.5 committed 2026-10-07 21:56:09 +05:00
1 parent e39cecb333
commit 95ab5dd9ef
27 files changed
+1830 -10

No files matched your search

+54
View File
@@ -984,6 +984,60 @@ const en = {
"fr.lan.unavailable": "Selected address unavailable",
"fr.lan.unavailableText": "The selected address is not currently assigned to a detected local interface. Choose another address or switch to Automatic, or keep this address intentionally.",
"fr.lan.invalid": "Invalid IPv4 address",
"nav.servers": "Servers",
"browse.title": "Servers",
"browse.text": "Public realms, as their owners publish them. Pick one to see its rates, modules and whether your character can play there.",
"browse.refresh": "Refresh",
"browse.noUrl": "Enter the Registry address above to see the public servers.",
"browse.empty": "No servers match.",
"browse.search": "Search by name",
"browse.mode": "Mode",
"browse.any": "any",
"browse.capMin": "Cap from",
"browse.capMax": "to",
"browse.module": "Module",
"browse.playersMin": "Players from",
"browse.col.server": "Server",
"browse.col.modules": "Modules",
"browse.col.cap": "Cap",
"browse.col.rates": "Rates",
"browse.col.mode": "Mode",
"browse.col.ping": "Ping",
"browse.col.online": "Online",
"browse.pingHint": "Not measured yet: ping needs a game route to the server, which is not available yet.",
"browse.more": "+{n}",
"browse.more.button": "Load more",
"browse.shown": "{n} servers shown",
"browse.players_one": "{n} player",
"browse.players_few": "{n} players",
"browse.players_many": "{n} players",
"browse.players_other": "{n} players",
"browse.bots_one": "{n} bot",
"browse.bots_few": "{n} bots",
"browse.bots_many": "{n} bots",
"browse.bots_other": "{n} bots",
"browse.cap": "Cap",
"browse.capacity": "limit {n}",
"browse.rates": "Rates",
"browse.rate.xp": "XP",
"browse.rate.xpQuest": "Quest XP",
"browse.rate.xpExplore": "Exploration XP",
"browse.rate.loot": "Loot",
"browse.rate.money": "Money",
"browse.rate.reputation": "Reputation",
"browse.rate.honor": "Honor",
"browse.modules": "Modules",
"browse.moduleOff": "(off)",
"browse.accounts": "Account",
"browse.accountsAutomatic": "Created for you automatically when you join.",
"browse.accountsExisting": "Link an account you already have on this server.",
"browse.compat": "Your character",
"browse.character": "Character",
"browse.noCharacter": "You have no portable character yet. Make one portable on the Characters page to see whether it can play here.",
"browse.canPlay": "Can play",
"browse.cannotPlay": "Cannot play here",
"browse.play": "Play",
"browse.playSoon": "Joining arrives with the account support of the next step.",
"registry.title": "Public listing",
"registry.text": "Publish this realm in the central list so that players can find it. Only its name, description, language, region, rates, modules, player counts, version and capabilities are shared: no passwords, no characters, no accounts. The realm keeps running if the list is unreachable.",
"registry.url": "Registry address",
+54
View File
@@ -982,6 +982,60 @@ const ru: Partial<Record<keyof typeof en, string>> = {
"fr.lan.unavailable": "Выбранный адрес недоступен",
"fr.lan.unavailableText": "Выбранный адрес сейчас не назначен обнаруженному сетевому интерфейсу. Выберите другой адрес, переключитесь на автоматический выбор или намеренно сохраните этот адрес.",
"fr.lan.invalid": "Некорректный IPv4-адрес",
"nav.servers": "Серверы",
"browse.title": "Серверы",
"browse.text": "Публичные реалмы в том виде, как их публикуют владельцы. Выберите сервер, чтобы увидеть рейты, модули и сможет ли там играть ваш персонаж.",
"browse.refresh": "Обновить",
"browse.noUrl": "Введите адрес реестра выше, чтобы увидеть публичные серверы.",
"browse.empty": "Подходящих серверов нет.",
"browse.search": "Поиск по названию",
"browse.mode": "Режим",
"browse.any": "любой",
"browse.capMin": "Кап от",
"browse.capMax": "до",
"browse.module": "Модуль",
"browse.playersMin": "Игроков от",
"browse.col.server": "Сервер",
"browse.col.modules": "Модули",
"browse.col.cap": "Кап",
"browse.col.rates": "Рейты",
"browse.col.mode": "Режим",
"browse.col.ping": "Пинг",
"browse.col.online": "Онлайн",
"browse.pingHint": "Пока не измеряется: для пинга нужен игровой маршрут до сервера, его пока нет.",
"browse.more": "+{n}",
"browse.more.button": "Показать ещё",
"browse.shown": "Показано серверов: {n}",
"browse.players_one": "{n} игрок",
"browse.players_few": "{n} игрока",
"browse.players_many": "{n} игроков",
"browse.players_other": "{n} игроков",
"browse.bots_one": "{n} бот",
"browse.bots_few": "{n} бота",
"browse.bots_many": "{n} ботов",
"browse.bots_other": "{n} ботов",
"browse.cap": "Кап",
"browse.capacity": "лимит {n}",
"browse.rates": "Рейты",
"browse.rate.xp": "Опыт",
"browse.rate.xpQuest": "Опыт за квесты",
"browse.rate.xpExplore": "Опыт за исследование",
"browse.rate.loot": "Добыча",
"browse.rate.money": "Деньги",
"browse.rate.reputation": "Репутация",
"browse.rate.honor": "Честь",
"browse.modules": "Модули",
"browse.moduleOff": "(выкл.)",
"browse.accounts": "Аккаунт",
"browse.accountsAutomatic": "Создаётся для вас автоматически при входе.",
"browse.accountsExisting": "Привяжите аккаунт, который у вас уже есть на этом сервере.",
"browse.compat": "Ваш персонаж",
"browse.character": "Персонаж",
"browse.noCharacter": "У вас пока нет переносимого персонажа. Сделайте его переносимым на странице «Персонажи», чтобы увидеть, сможет ли он играть здесь.",
"browse.canPlay": "Можно играть",
"browse.cannotPlay": "Здесь играть нельзя",
"browse.play": "Играть",
"browse.playSoon": "Вход на сервер появится вместе с поддержкой аккаунтов на следующем шаге.",
"registry.title": "Публичный список",
"registry.text": "Опубликуйте этот реалм в общем списке, чтобы игроки могли его найти. Передаются только название, описание, язык, регион, рейты, модули, число игроков и ботов, версия и возможности реалма: никаких паролей, персонажей и аккаунтов. Если список недоступен, реалм продолжает работать.",
"registry.url": "Адрес реестра",
+80
View File
@@ -0,0 +1,80 @@
import { invoke } from "@tauri-apps/api/core";
export interface Rates {
xp_kill: number | null;
xp_quest: number | null;
xp_explore: number | null;
loot: number | null;
money: number | null;
reputation: number | null;
honor: number | null;
}
export interface ModuleEntry { id: string; version: string | null; enabled: boolean }
export interface Population { players: number; bots: number; capacity: number | null }
export interface AccountProvisioning { automatic: boolean; existing_only: boolean }
export type Ruleset = "coa" | "wildcard";
export interface RealmSummary {
realm_id: string;
display_name: string;
description: string;
language: string;
region: string | null;
ruleset: Ruleset;
level_cap: number | null;
rates: Rates;
modules: ModuleEntry[];
population: Population;
account_provisioning: AccountProvisioning;
manager_version: string;
capabilities_hash: string;
listing_hash: string;
metadata_revision: number;
online: boolean;
created_at: number;
last_seen_at: number;
}
export interface RealmPage { realms: RealmSummary[]; next_cursor: string | null }
export interface RealmDetail {
realm_id: string;
public_key: string;
listing: { display_name: string; description: string; language: string; region: string | null; rates: Rates; modules: ModuleEntry[]; account_provisioning: AccountProvisioning; manager_version: string };
ruleset: Ruleset;
level_cap: number | null;
population: Population;
capabilities: unknown;
metadata_revision: number;
online: boolean;
last_seen_at: number;
}
export interface ModuleInfo { id: string; name: string; description: Record<string, string>; status: string; icon: string }
export type SortKey = "name" | "players" | "cap" | "created";
export interface BrowseParams {
q?: string;
ruleset?: Ruleset;
cap_min?: number;
cap_max?: number;
module?: string;
players_min?: number;
status?: "online" | "offline" | "all";
sort?: SortKey;
order?: "asc" | "desc";
cursor?: string;
limit?: number;
}
export const browse = {
list: (params: BrowseParams) => invoke<RealmPage>("browse_list", { params }),
detail: (realmId: string) => invoke<RealmDetail>("browse_detail", { realmId }),
modules: () => invoke<ModuleInfo[]>("module_catalog"),
};
/** `×2`, `×1.5`; unknown is a dash, never a guess. */
export function rate(v: number | null): string {
return v === null ? "—" : `×${Number.isInteger(v) ? v : Number(v.toFixed(2))}`;
}
+1
View File
@@ -102,6 +102,7 @@ export const portable = {
addRealm: (path: string) => invoke<RealmView>("portable_add_realm", { path }),
removeRealm: (realm: string) => invoke<void>("portable_remove_realm", { realm }),
diagnostics: () => invoke<unknown>("portable_diagnostics"),
preflightRemote: (character: string, capabilities: unknown) => invoke<PreflightView>("portable_preflight_remote", { character, capabilities }),
launch: (realm: string) => invoke<void>("portable_launch", { realm }),
};
+278
View File
@@ -0,0 +1,278 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { ArrowDown, ArrowUp, Loader2, RefreshCw, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { useI18n, type Key } from "@/i18n";
import { asUiError } from "@/lib/api";
import { realmRegistry, useRegistryStatus } from "@/lib/registry";
import { asPortableError, portable, usePortable, type PreflightView } from "@/lib/portable";
import { Notes, Projection } from "@/screens/PortablePage";
import { browse, rate, type BrowseParams, type ModuleEntry, type ModuleInfo, type RealmDetail, type RealmSummary, type SortKey } from "@/lib/browse";
const VISIBLE_MODULES = 3;
const PAGE = 50;
type Catalog = Record<string, ModuleInfo>;
/** A module chip. A module the local catalog knows gets its name and a tooltip from the catalog; any other id is shown as the plain text it is. */
function ModuleChip({ m, catalog }: { m: ModuleEntry; catalog: Catalog }) {
const { locale } = useI18n();
const known = catalog[m.id];
const name = known?.name ?? m.id;
const description = known ? known.description[locale] ?? known.description.en ?? "" : "";
return <span className="group relative inline-block" tabIndex={0}>
<span className={cn("inline-flex items-center rounded-full border px-2 py-0.5 text-xs", m.enabled ? "border-line bg-white/5 text-ink" : "border-line/60 text-muted line-through")}>{name}</span>
<span role="tooltip" className="pointer-events-none absolute left-0 top-full z-30 mt-1 hidden w-64 rounded-md border border-line bg-card p-3 text-left text-xs shadow-lg group-hover:block group-focus:block">
<span className="block text-sm font-semibold text-ink">{name}</span>
{description && <span className="mt-1 block text-muted">{description}</span>}
{m.version && <span className="mt-1 block text-muted">{m.version}</span>}
{!known && <span className="mt-1 block text-muted">{m.id}</span>}
</span>
</span>;
}
function Modules({ modules, catalog }: { modules: ModuleEntry[]; catalog: Catalog }) {
const { t } = useI18n();
const on = modules.filter((m) => m.enabled);
if (on.length === 0) return <span className="text-muted">—</span>;
return <span className="flex flex-wrap items-center gap-1">
{on.slice(0, VISIBLE_MODULES).map((m) => <ModuleChip key={m.id} m={m} catalog={catalog} />)}
{on.length > VISIBLE_MODULES && <span className="text-xs text-muted" title={on.slice(VISIBLE_MODULES).map((m) => catalog[m.id]?.name ?? m.id).join(", ")}>{t("browse.more", { n: on.length - VISIBLE_MODULES })}</span>}
</span>;
}
function Online({ p }: { p: RealmSummary["population"] }) {
const { tn } = useI18n();
return <span className="whitespace-nowrap">{tn("browse.players", p.players)}<span className="text-muted"> + </span>{tn("browse.bots", p.bots)}</span>;
}
function Mode({ ruleset }: { ruleset: string }) {
return <span>{ruleset === "wildcard" ? "Wildcard" : "CoA"}</span>;
}
function compactRates(r: RealmSummary["rates"], t: (k: Key, v?: Record<string, string | number>) => string): string {
return `${t("browse.rate.xp")} ${rate(r.xp_kill)} · ${t("browse.rate.loot")} ${rate(r.loot)}`;
}
const RATE_ROWS: [keyof RealmSummary["rates"], Key][] = [["xp_kill", "browse.rate.xp"], ["xp_quest", "browse.rate.xpQuest"], ["xp_explore", "browse.rate.xpExplore"], ["loot", "browse.rate.loot"], ["money", "browse.rate.money"], ["reputation", "browse.rate.reputation"], ["honor", "browse.rate.honor"]];
function SortHeader({ id, sort, order, onSort, children, className }: { id: SortKey; sort: SortKey; order: "asc" | "desc"; onSort: (k: SortKey) => void; children: React.ReactNode; className?: string }) {
const active = sort === id;
return <th scope="col" aria-sort={active ? (order === "asc" ? "ascending" : "descending") : "none"} className={cn("px-3 py-2 text-left font-medium", className)}>
<button onClick={() => onSort(id)} className={cn("inline-flex cursor-pointer items-center gap-1 hover:text-ink", active ? "text-ink" : "text-muted")}>{children}{active && (order === "asc" ? <ArrowUp className="h-3.5 w-3.5" aria-hidden /> : <ArrowDown className="h-3.5 w-3.5" aria-hidden />)}</button>
</th>;
}
function Drawer({ summary, catalog, onClose }: { summary: RealmSummary; catalog: Catalog; onClose: () => void }) {
const { t } = useI18n();
const { state } = usePortable();
const [detail, setDetail] = useState<RealmDetail | null>(null);
const [error, setError] = useState<string | null>(null);
const [character, setCharacter] = useState("");
const [pre, setPre] = useState<PreflightView | null>(null);
const [preError, setPreError] = useState<string | null>(null);
const characters = state?.characters ?? [];
useEffect(() => {
let alive = true;
setDetail(null); setError(null);
void browse.detail(summary.realm_id).then((d) => { if (alive) setDetail(d); }).catch((e) => { if (alive) setError(asUiError(e).technical); });
return () => { alive = false; };
}, [summary.realm_id]);
useEffect(() => { if (!character && characters.length > 0) setCharacter(characters[0].id); }, [characters.length]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
if (!character || !detail) { setPre(null); return; }
let alive = true;
setPreError(null);
void portable.preflightRemote(character, detail.capabilities).then((p) => { if (alive) setPre(p); }).catch((e) => { if (alive) { setPre(null); setPreError(asPortableError(e).message); } });
return () => { alive = false; };
}, [character, detail?.realm_id, detail?.metadata_revision]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); };
window.addEventListener("keydown", onKey);
return () => window.removeEventListener("keydown", onKey);
}, [onClose]);
const d = detail;
const chosen = characters.find((c) => c.id === character);
const blocked = pre?.verdict === "incompatible";
return <aside role="complementary" aria-label={summary.display_name} className="fixed inset-y-0 right-0 z-40 flex w-[440px] max-w-full flex-col border-l border-line bg-[#0e1013] shadow-2xl">
<div className="flex items-start justify-between gap-3 border-b border-line p-5">
<div className="min-w-0">
<h2 className="truncate text-lg font-semibold" data-testid="drawer-title">{summary.display_name}</h2>
<p className="mt-0.5 text-sm text-muted"><Mode ruleset={summary.ruleset} /> · {t("browse.cap")} {summary.level_cap ?? "—"}</p>
<p className="text-sm"><Online p={summary.population} />{summary.population.capacity !== null && <span className="text-muted"> · {t("browse.capacity", { n: summary.population.capacity })}</span>}</p>
</div>
<button onClick={onClose} aria-label={t("portable.close")} className="cursor-pointer text-muted hover:text-ink"><X className="h-5 w-5" /></button>
</div>
<div className="flex-1 space-y-5 overflow-y-auto p-5 text-sm">
{summary.description && <p className="whitespace-pre-wrap break-words text-muted">{d?.listing.description ?? summary.description}</p>}
<section>
<h3 className="mb-1 font-medium">{t("browse.rates")}</h3>
<dl className="grid grid-cols-2 gap-x-4 gap-y-0.5">
{RATE_ROWS.map(([k, label]) => <div key={k} className="flex justify-between border-b border-line/40 py-0.5"><dt className="text-muted">{t(label)}</dt><dd>{rate(summary.rates[k])}</dd></div>)}
</dl>
</section>
<section>
<h3 className="mb-1 font-medium">{t("browse.modules")}</h3>
{summary.modules.length === 0 ? <p className="text-muted">—</p> : <ul className="space-y-1.5">
{summary.modules.map((m) => <li key={m.id} className="flex items-baseline justify-between gap-3"><span className={cn(!m.enabled && "text-muted line-through")}>{catalog[m.id]?.name ?? m.id}</span><span className="text-xs text-muted">{m.version ?? ""}{!m.enabled && ` ${t("browse.moduleOff")}`}</span></li>)}
</ul>}
</section>
<section>
<h3 className="mb-1 font-medium">{t("browse.accounts")}</h3>
<p className="text-muted">{summary.account_provisioning.automatic ? t("browse.accountsAutomatic") : t("browse.accountsExisting")}</p>
</section>
<section>
<h3 className="mb-1 font-medium">{t("browse.compat")}</h3>
{error && <p className="text-bad" role="alert">{error}</p>}
{!error && !d && <p className="flex items-center gap-2 text-muted"><Loader2 className="h-4 w-4 animate-spin" aria-hidden />{t("portable.make.loading")}</p>}
{characters.length === 0 && <p className="text-muted">{t("browse.noCharacter")}</p>}
{characters.length > 0 && <>
<select aria-label={t("browse.character")} value={character} onChange={(e) => setCharacter(e.target.value)} className="w-full rounded-md border border-line bg-card px-3 py-2">
{characters.map((c) => <option key={c.id} value={c.id}>{c.name} — {c.class_name}, {t("portable.level", { level: c.level })}</option>)}
</select>
{preError && <p className="mt-2 text-warn">{preError}</p>}
{pre && chosen && <div className={cn("mt-2 rounded-md border p-3", blocked ? "border-bad/50 bg-bad/10" : pre.verdict === "degraded" ? "border-warn/50 bg-warn/10" : "border-ok/40 bg-ok/10")} data-verdict={pre.verdict}>
<p className="font-medium">{blocked ? t("browse.cannotPlay") : t("browse.canPlay")}</p>
{pre.projection && <Projection from={pre.projection[0]} to={pre.projection[1]} cap={summary.level_cap} />}
<Notes notes={pre.notes} />
</div>}
</>}
</section>
</div>
<div className="border-t border-line p-5">
<Button variant="primary" className="w-full" disabled>{t("browse.play")}</Button>
<p className="mt-2 text-xs text-muted">{t("browse.playSoon")}</p>
</div>
</aside>;
}
export function BrowsePage() {
const { t } = useI18n();
const { status, refresh } = useRegistryStatus(5000);
const [url, setUrl] = useState("");
const [q, setQ] = useState("");
const [ruleset, setRuleset] = useState<"" | "coa" | "wildcard">("");
const [capMin, setCapMin] = useState("");
const [capMax, setCapMax] = useState("");
const [module, setModule] = useState("");
const [playersMin, setPlayersMin] = useState("");
const [sort, setSort] = useState<SortKey>("players");
const [order, setOrder] = useState<"asc" | "desc">("desc");
const [rows, setRows] = useState<RealmSummary[]>([]);
const [next, setNext] = useState<string | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [selected, setSelected] = useState<RealmSummary | null>(null);
const [catalog, setCatalog] = useState<Catalog>({});
const ticket = useRef(0);
useEffect(() => { void browse.modules().then((m) => setCatalog(Object.fromEntries(m.map((x) => [x.id, x])))).catch(() => {}); }, []);
useEffect(() => { if (status?.url && url === "") setUrl(status.url); }, [status?.url]); // eslint-disable-line react-hooks/exhaustive-deps
const params = useMemo<BrowseParams>(() => ({
q: q.trim() || undefined,
ruleset: ruleset || undefined,
cap_min: capMin !== "" && !Number.isNaN(Number(capMin)) ? Number(capMin) : undefined,
cap_max: capMax !== "" && !Number.isNaN(Number(capMax)) ? Number(capMax) : undefined,
module: module || undefined,
players_min: playersMin !== "" && !Number.isNaN(Number(playersMin)) ? Number(playersMin) : undefined,
sort, order, limit: PAGE,
}), [q, ruleset, capMin, capMax, module, playersMin, sort, order]);
const load = useCallback(async (cursor?: string) => {
const mine = ++ticket.current;
setLoading(true);
setError(null);
try {
const page = await browse.list({ ...params, cursor });
if (mine !== ticket.current) return;
setRows((old) => (cursor ? [...old, ...page.realms] : page.realms));
setNext(page.next_cursor);
} catch (e) {
if (mine !== ticket.current) return;
setError(asUiError(e).technical);
if (!cursor) { setRows([]); setNext(null); }
} finally { if (mine === ticket.current) setLoading(false); }
}, [params]);
useEffect(() => {
if (!status?.url) return;
const timer = setTimeout(() => void load(), q ? 300 : 0);
return () => clearTimeout(timer);
}, [load, status?.url]); // eslint-disable-line react-hooks/exhaustive-deps
function onSort(k: SortKey) {
if (k === sort) setOrder((o) => (o === "asc" ? "desc" : "asc"));
else { setSort(k); setOrder(k === "name" ? "asc" : "desc"); }
}
const moduleChoices = useMemo(() => Object.values(catalog).filter((m) => m.id !== "client-compat").sort((a, b) => a.name.localeCompare(b.name)), [catalog]);
const noUrl = !status?.url;
return <div className="relative">
<div className="flex items-start justify-between gap-4">
<div>
<h1 className="text-2xl font-semibold">{t("browse.title")}</h1>
<p className="mt-1 text-sm text-muted">{t("browse.text")}</p>
</div>
<Button size="sm" onClick={() => void load()} disabled={loading || noUrl}>{loading ? <Loader2 className="h-4 w-4 animate-spin" aria-hidden /> : <RefreshCw className="h-4 w-4" aria-hidden />}{t("browse.refresh")}</Button>
</div>
<div className="mt-4 flex gap-2">
<input aria-label={t("registry.url")} value={url} onChange={(e) => setUrl(e.target.value)} placeholder="https://registry.example" className="min-w-0 flex-1 rounded-md border border-line bg-card px-3 py-2 text-sm" />
<Button size="sm" disabled={url.trim() === (status?.url ?? "")} onClick={() => void realmRegistry.setUrl(url.trim() || null).then(refresh).catch((e) => setError(asUiError(e).technical))}>{t("registry.urlSave")}</Button>
</div>
{noUrl && <p className="mt-2 text-sm text-muted">{t("browse.noUrl")}</p>}
<div className="mt-4 grid grid-cols-2 gap-3 md:grid-cols-6">
<input aria-label={t("browse.search")} value={q} onChange={(e) => setQ(e.target.value)} placeholder={t("browse.search")} className="col-span-2 rounded-md border border-line bg-card px-3 py-2 text-sm" />
<select aria-label={t("browse.mode")} value={ruleset} onChange={(e) => setRuleset(e.target.value as "" | "coa" | "wildcard")} className="rounded-md border border-line bg-card px-3 py-2 text-sm">
<option value="">{t("browse.mode")}: {t("browse.any")}</option><option value="coa">CoA</option><option value="wildcard">Wildcard</option>
</select>
<div className="flex items-center gap-1 text-sm"><input aria-label={t("browse.capMin")} inputMode="numeric" value={capMin} onChange={(e) => setCapMin(e.target.value.replace(/\D/g, ""))} placeholder={t("browse.capMin")} className="w-full rounded-md border border-line bg-card px-2 py-2" /><span className="text-muted">–</span><input aria-label={t("browse.capMax")} inputMode="numeric" value={capMax} onChange={(e) => setCapMax(e.target.value.replace(/\D/g, ""))} placeholder={t("browse.capMax")} className="w-full rounded-md border border-line bg-card px-2 py-2" /></div>
<select aria-label={t("browse.module")} value={module} onChange={(e) => setModule(e.target.value)} className="rounded-md border border-line bg-card px-3 py-2 text-sm">
<option value="">{t("browse.module")}: {t("browse.any")}</option>
{moduleChoices.map((m) => <option key={m.id} value={m.id}>{m.name}</option>)}
</select>
<input aria-label={t("browse.playersMin")} inputMode="numeric" value={playersMin} onChange={(e) => setPlayersMin(e.target.value.replace(/\D/g, ""))} placeholder={t("browse.playersMin")} className="rounded-md border border-line bg-card px-3 py-2 text-sm" />
</div>
{error && <p className="mt-3 text-sm text-bad" role="alert">{error}</p>}
<div className="mt-4 overflow-x-auto rounded-lg border border-line">
<table className="w-full min-w-[760px] text-sm" data-testid="realm-table">
<thead className="bg-white/[0.03] text-xs uppercase tracking-wide">
<tr>
<SortHeader id="name" sort={sort} order={order} onSort={onSort}>{t("browse.col.server")}</SortHeader>
<th scope="col" className="px-3 py-2 text-left font-medium text-muted">{t("browse.col.modules")}</th>
<SortHeader id="cap" sort={sort} order={order} onSort={onSort}>{t("browse.col.cap")}</SortHeader>
<th scope="col" className="px-3 py-2 text-left font-medium text-muted">{t("browse.col.rates")}</th>
<th scope="col" className="px-3 py-2 text-left font-medium text-muted">{t("browse.col.mode")}</th>
<th scope="col" className="px-3 py-2 text-left font-medium text-muted" title={t("browse.pingHint")}>{t("browse.col.ping")}</th>
<SortHeader id="players" sort={sort} order={order} onSort={onSort}>{t("browse.col.online")}</SortHeader>
</tr>
</thead>
<tbody>
{rows.map((r) => <tr key={r.realm_id} onClick={() => setSelected(r)} onKeyDown={(e) => { if (e.key === "Enter") setSelected(r); }} tabIndex={0} aria-selected={selected?.realm_id === r.realm_id} className={cn("cursor-pointer border-t border-line/60 hover:bg-white/[0.04] focus:bg-white/[0.06] focus:outline-none", selected?.realm_id === r.realm_id && "bg-white/[0.06]")}>
<td className="max-w-[200px] px-3 py-2"><div className="truncate font-medium" title={r.display_name}>{r.display_name}</div><div className="truncate text-xs text-muted">{[r.region, r.language].filter(Boolean).join(" · ")}</div></td>
<td className="px-3 py-2"><Modules modules={r.modules} catalog={catalog} /></td>
<td className="px-3 py-2">{r.level_cap ?? "—"}</td>
<td className="whitespace-nowrap px-3 py-2">{compactRates(r.rates, t)}</td>
<td className="px-3 py-2"><Mode ruleset={r.ruleset} /></td>
<td className="px-3 py-2 text-muted" title={t("browse.pingHint")}>—</td>
<td className="px-3 py-2"><Online p={r.population} /></td>
</tr>)}
{rows.length === 0 && !loading && <tr><td colSpan={7} className="px-3 py-8 text-center text-muted">{noUrl ? t("browse.noUrl") : t("browse.empty")}</td></tr>}
</tbody>
</table>
</div>
<div className="mt-3 flex items-center gap-3 text-sm text-muted">
{loading && <span className="flex items-center gap-2"><Loader2 className="h-4 w-4 animate-spin" aria-hidden />{t("portable.make.loading")}</span>}
{!loading && rows.length > 0 && <span>{t("browse.shown", { n: rows.length })}</span>}
{next && !loading && <Button size="sm" onClick={() => void load(next)}>{t("browse.more.button")}</Button>}
</div>
{selected && <Drawer summary={selected} catalog={catalog} onClose={() => setSelected(null)} />}
</div>;
}
+2 -2
View File
@@ -42,14 +42,14 @@ function noteText(t: ReturnType<typeof useT>, n: Note): string {
return text === key ? t("portable.note.generic", { detail: n.detail }) : text;
}
function Notes({ notes }: { notes: Note[] }) {
export function Notes({ notes }: { notes: Note[] }) {
const t = useT();
const shown = notes.filter((n) => n.code !== "projection");
if (!shown.length) return null;
return <ul className="mt-3 space-y-1.5 text-sm text-muted">{shown.map((n, i) => <li key={i} className="flex gap-2"><AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-warn" aria-hidden /><span className="selectable">{noteText(t, n)}</span></li>)}</ul>;
}
function Projection({ from, to, cap }: { from: number; to: number; cap?: number | null }) {
export function Projection({ from, to, cap }: { from: number; to: number; cap?: number | null }) {
const t = useT();
return <div className="mt-3 rounded-md border border-gold/40 bg-gold/10 p-3 text-sm" role="note">
<p className="font-medium text-gold">{t("portable.projection.title", { cap: cap ?? to })}</p>
+6 -5
View File
@@ -1,11 +1,12 @@
import { useEffect, useState } from "react";
import { Gauge, Settings, Swords } from "lucide-react";
import { Gauge, Globe, Settings, Swords } from "lucide-react";
import { api, asUiError, REMOTE_CLIENT_ID } from "@/lib/api";
import { checkClient, startClientPolling, useClientStatus } from "@/lib/clientUpdate";
import { ClientCard } from "@/screens/ClientCard";
import { ClientDialog, type ClientDialogMode } from "@/screens/ClientDialog";
import { AboutCard } from "@/screens/AboutCard";
import { PortablePage } from "@/screens/PortablePage";
import { BrowsePage } from "@/screens/BrowsePage";
import { LanguagePicker } from "@/components/LanguagePicker";
import { Button } from "@/components/ui/button";
import { Card } from "@/components/ui/card";
@@ -16,7 +17,7 @@ import logo from "@/assets/logo.png";
export function RemoteClient({ onHost }: { onHost: () => void }) {
const t = useT();
const human = useHuman();
const [page, setPage] = useState<"overview" | "characters" | "settings">("overview");
const [page, setPage] = useState<"servers" | "overview" | "characters" | "settings">("servers");
const [host, setHost] = useState("");
const [savedHost, setSavedHost] = useState("");
const [loading, setLoading] = useState(true);
@@ -57,14 +58,14 @@ export function RemoteClient({ onHost }: { onHost: () => void }) {
<nav className="flex w-60 shrink-0 flex-col border-r border-line bg-[#0b0c0e] p-3" aria-label={t("nav.main")}>
<div className="flex items-center gap-2 px-3 pb-4 pt-2 text-sm font-semibold tracking-wide text-gold"><img src={logo} alt="" className="h-7 w-7" />{t("app.name")}</div>
<ul className="flex flex-col gap-0.5">
{(["overview", "characters", "settings"] as const).map(id => { const Icon = id === "overview" ? Gauge : id === "characters" ? Swords : Settings; return <li key={id}>
<button onClick={() => setPage(id)} aria-current={page === id ? "page" : undefined} className={cn("flex h-10 w-full cursor-pointer items-center gap-3 rounded-md px-3 text-left text-[15px]", page === id ? "bg-white/[0.07] text-ink" : "text-muted hover:bg-white/5 hover:text-ink")}><Icon className="h-[18px] w-[18px]" aria-hidden />{t(id === "overview" ? "nav.overview" : id === "characters" ? "nav.characters" : "nav.settings")}</button>
{(["servers", "overview", "characters", "settings"] as const).map(id => { const Icon = id === "servers" ? Globe : id === "overview" ? Gauge : id === "characters" ? Swords : Settings; return <li key={id}>
<button onClick={() => setPage(id)} aria-current={page === id ? "page" : undefined} className={cn("flex h-10 w-full cursor-pointer items-center gap-3 rounded-md px-3 text-left text-[15px]", page === id ? "bg-white/[0.07] text-ink" : "text-muted hover:bg-white/5 hover:text-ink")}><Icon className="h-[18px] w-[18px]" aria-hidden />{t(id === "servers" ? "nav.servers" : id === "overview" ? "nav.overview" : id === "characters" ? "nav.characters" : "nav.settings")}</button>
</li>; })}
</ul>
<div className="mt-auto border-t border-line pt-3"><Button variant="ghost" size="sm" className="w-full justify-start" onClick={onHost}>{t("remote.hostInstead")}</Button></div>
</nav>
<main className="h-full flex-1 overflow-y-auto px-10 py-8">
{page === "characters" ? <PortablePage /> : page === "settings" ? <><div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("nav.settings")}</h1><LanguagePicker /></div><AboutCard /></> : <>
{page === "servers" ? <BrowsePage /> : page === "characters" ? <PortablePage /> : page === "settings" ? <><div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("nav.settings")}</h1><LanguagePicker /></div><AboutCard /></> : <>
<div className="flex items-center justify-between"><h1 className="text-2xl font-semibold">{t("welcome.connect.title")}</h1><LanguagePicker /></div>
<p className="mt-2 text-muted">{t("remote.intro")}</p>
<Card className="mt-6 p-6">