Files
punktfunk/web/src/sections/Dashboard/RunningGames.tsx
T
enricobuehler 39a9f09f04
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 1m46s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 33s
ci / web (push) Successful in 56s
decky / build-publish (push) Successful in 1m1s
docker / build-push (ci, ci/rust-ci-noble.Dockerfile, punktfunk-rust-ci-noble) (push) Successful in 31s
deb / build-publish-client-arm64 (push) Successful in 8m0s
windows-host / package (push) Failing after 35s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 31s
deb / build-publish-host (push) Successful in 10m43s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 33s
windows-host / winget-source (push) Skipped
ci / docs-site (push) Successful in 1m57s
arch / build-publish (push) Successful in 13m21s
android / android (push) Successful in 17m20s
ci / rust-arm64 (push) Successful in 13m46s
deb / build-publish (push) Successful in 14m47s
ci / rust (push) Successful in 21m52s
rpm / build-publish (44, fedora-44, punktfunk-fedora44-rpm) (push) Successful in 25m39s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 30s
ci / bench (push) Successful in 6m13s
rpm / build-publish (43, bazzite, punktfunk-fedora-rpm) (push) Successful in 19m21s
docker / build-push-arm64cross (push) Successful in 8m21s
docker / deploy-docs (push) Successful in 40s
apple / swift (push) Successful in 5m37s
apple / screenshots (push) Successful in 23m3s
fix(mgmt/web): the running-game cover slot says "game" when there is no art
Rendered the Dashboard stories headlessly and looked at them, which is how this
turned up: with no cover the slot was an empty grey rectangle, reading as
something that failed to load rather than something absent.

Plenty of rows will never have art — an operator-typed command has no catalog
entry behind it, a custom entry may carry none, and nothing does until
`/library` has loaded. The slot keeps its fixed size so rows stay aligned when
only some titles have covers; it just holds a gamepad glyph instead of nothing.
2026-07-27 00:47:05 +02:00

145 lines
4.8 KiB
TypeScript

import { Gamepad2, XCircle } from "lucide-react";
import type { FC } from "react";
import type { ActiveGame } from "@/api/gen/model/activeGame";
import type { GameEntry } from "@/api/gen/model/gameEntry";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { m } from "@/paraglide/messages";
/**
* What the host is running, and — when a client has vanished — how long its game has left.
*
* The `grace` rows are the reason this card exists at all. A game whose session is gone is on a
* countdown to being closed, which costs unsaved progress; that has to be visible somewhere, with a
* way to say "yes, do it now" or (by reconnecting) "no". The live rows come almost free alongside.
*/
export const RunningGames: FC<{
games: ActiveGame[];
/** The catalog, for box art — matched by `app_id`. Absent while `/library` is still loading. */
library?: GameEntry[];
onEnd: (game: ActiveGame) => void;
isEnding: boolean;
}> = ({ games, library, onEnd, isEnding }) => {
if (games.length === 0) return null;
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Gamepad2 className="size-4" />
{m.games_title()}
</CardTitle>
</CardHeader>
<CardContent className="flex flex-col gap-3">
{games.map((g) => (
<GameRow
// A host can run the same title for two clients at once (native admits concurrent
// sessions), so the title alone is not a key.
key={`${g.plane}:${g.session_id ?? "grace"}:${g.app_id ?? g.title}`}
game={g}
art={coverFor(g, library)}
onEnd={() => onEnd(g)}
isEnding={isEnding}
/>
))}
</CardContent>
</Card>
);
};
const GameRow: FC<{
game: ActiveGame;
art?: string;
onEnd: () => void;
isEnding: boolean;
}> = ({ game, art, onEnd, isEnding }) => {
const waiting = game.state === "grace";
return (
<div className="flex items-center gap-3">
{/* Fixed slot so rows line up whether or not a title has a cover. Plenty won't: an
operator-typed command has no catalog entry behind it, a custom entry may carry no
art, and nothing does until `/library` has loaded — an empty box reads as broken, so
the placeholder says "game" instead of nothing. */}
<div className="flex h-16 w-11 shrink-0 items-center justify-center overflow-hidden rounded bg-muted">
{art ? (
<img
src={art}
alt=""
loading="lazy"
className="size-full object-cover"
/>
) : (
<Gamepad2 className="size-5 text-muted-foreground/60" />
)}
</div>
<div className="min-w-0 flex-1">
<div className="flex flex-wrap items-center gap-2">
<span className="truncate font-medium">{game.title}</span>
<Badge variant={waiting ? "destructive" : stateVariant(game.state)}>
{stateLabel(game.state)}
</Badge>
</div>
<p className="mt-0.5 truncate text-xs text-muted-foreground">
{waiting
? m.games_closing_in({
time: formatCountdown(game.grace_remaining_s ?? 0),
})
: [game.client, planeLabel(game.plane)].filter(Boolean).join(" · ")}
</p>
</div>
<Button
variant={waiting ? "destructive" : "outline"}
size="sm"
disabled={isEnding}
onClick={onEnd}
>
<XCircle className="size-3.5" />
{m.games_end_now()}
</Button>
</div>
);
};
/**
* Box art for a running game, matched against the already-fetched catalog by store-qualified id —
* so this card costs no extra request. `undefined` for an operator-typed GameStream command (no
* catalog entry behind it) or a title whose entry carries no art.
*/
function coverFor(game: ActiveGame, library?: GameEntry[]): string | undefined {
if (!game.app_id || !library) return undefined;
const entry = library.find((e) => e.id === game.app_id);
return entry?.art.portrait ?? entry?.art.header ?? undefined;
}
/** `mm:ss` — the countdown reads as a duration, not a number of seconds. */
function formatCountdown(seconds: number): string {
const s = Math.max(0, Math.floor(seconds));
return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, "0")}`;
}
function stateLabel(state: string): string {
switch (state) {
case "launching":
return m.games_state_launching();
case "running":
return m.games_state_running();
case "exited":
return m.games_state_exited();
case "grace":
return m.games_state_grace();
default:
return state;
}
}
function stateVariant(state: string): "success" | "secondary" | "outline" {
if (state === "running") return "success";
if (state === "launching") return "secondary";
return "outline";
}
/** The compat plane is worth naming: it is why a row may show an IP instead of a device name. */
function planeLabel(plane: string): string {
return plane === "gamestream" ? "GameStream" : "";
}