Upload chip redesign

This commit is contained in:
Kalle
2026-09-20 13:57:30 +03:00
parent 84db5e3c02
commit d3bb24737d
8 changed files with 325 additions and 267 deletions

View File

@@ -57,8 +57,8 @@ opens it, for anyone, through the same handoff Inspect uses.
unlinked matches on a backoff (`sendou-ingest.ts`) and flushes closed
matches whose send was skipped; Stop sends what is left. VoD: the whole
scan sends once saved. Both write per-event send statuses to their own
store (`updateEventsSend` takes the store), so the cards' upload chip
(`UploadChip.tsx`) and the per-card Retry/Upload are one code path.
store (`updateEventsSend` takes the store), so the cards' upload status
button (`UploadStatus.tsx`) and its Retry/Upload are one code path.
- **CSV** is a normal feature: `⇩ CSV` in every session header offers
`Matches` (`core/csv/matches.ts`, one row per game, the rows the cards
render) and `Raw detections` (`core/csv/events.ts`, one row per event).

View File

@@ -266,7 +266,7 @@
}
/* the shared circle button, translucent over the banner */
button.expand {
button.circle {
flex-shrink: 0;
width: 28px;
height: 28px;
@@ -276,7 +276,6 @@ button.expand {
background: color-mix(in oklab, var(--color-bg) 55%, transparent);
backdrop-filter: blur(8px);
color: var(--color-text-high);
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
& svg {
width: var(--field-size-icon);
@@ -287,17 +286,16 @@ button.expand {
color: var(--color-text);
background: color-mix(in oklab, var(--color-bg) 78%, transparent);
}
}
button.expand {
transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
&.expanded {
transform: rotate(180deg);
}
}
.error {
font-size: var(--font-2xs);
color: var(--color-error);
}
/* the expanded content, indented under its card via a rail */
.details {
display: flex;

View File

@@ -1,7 +1,8 @@
/**
* One game of a session or file, the same card in every view. Collapsed it
* is one row: mode and stage, the result, the POV weapon and K/D/S, then
* the game's clips and its upload state. Expanded it shows the data and
* the game's clips and, once the game is over, its upload state beside the
* expand arrow. Expanded it shows the data and
* nothing interpreted: the scoreboard, the objective + player-status
* timeline, deaths and kills (each with a ▶ when a clip covers it) and the
* builds read for both teams.
@@ -40,7 +41,7 @@ import styles from "./MatchCard.module.css";
import { playerStatusTeams } from "./player-status-view";
import { RawDetections } from "./RawDetections";
import type { ScanEvent, SessionKind } from "./session-data";
import { UploadChip, type UploadState } from "./UploadChip";
import { type UploadState, UploadStatusButton } from "./UploadStatus";
/** the game score a knockout wins at */
const KO_MATCH_SCORE = 100;
@@ -166,7 +167,6 @@ export function MatchCard({
{pov.ka ?? "?"}/{pov.d ?? "?"}/{pov.s ?? "?"}
</span>
) : null}
<UploadChip state={upload} />
</div>
</div>
<div className={styles.foot}>
@@ -189,24 +189,24 @@ export function MatchCard({
))}
</span>
) : null}
<span className={styles.footEnd}>
{expandable ? (
{expandable ? (
<span className={styles.footEnd}>
<UploadStatusButton state={upload} className={styles.circle} />
<SendouButton
variant="minimal"
size="small"
shape="circle"
icon={<ChevronDown />}
className={clsx(styles.expand, { [styles.expanded]: expanded })}
className={clsx(styles.circle, styles.expand, {
[styles.expanded]: expanded,
})}
aria-expanded={expanded}
aria-label={expanded ? "Hide details" : "Show details"}
onClick={() => setExpanded(!expanded)}
/>
) : null}
</span>
</span>
) : null}
</div>
{upload.kind === "failed" && upload.error ? (
<div className={styles.error}>{upload.error}</div>
) : null}
</div>
);

View File

@@ -35,7 +35,7 @@ import { MatchCard } from "./MatchCard";
import styles from "./SessionView.module.css";
import { aggregateSendStatus } from "./sendou-ingest";
import type { ScanEvent, SessionKind } from "./session-data";
import { uploadStateOf } from "./UploadChip";
import { uploadStateOf } from "./UploadStatus";
import { useDebug } from "./use-debug";
const NO_KEYS: ReadonlySet<React.Key> = new Set();

View File

@@ -1,90 +0,0 @@
.chip {
display: inline-flex;
align-items: center;
gap: var(--s-1-5);
padding: var(--s-0-5) var(--s-2-5);
border-radius: var(--radius-full);
font-size: var(--font-2xs);
font-weight: var(--weight-bold);
border: var(--border-style);
background-color: var(--color-bg);
color: var(--color-text-high);
white-space: nowrap;
& .dot {
width: 7px;
height: 7px;
border-radius: var(--radius-full);
background: currentColor;
animation: scanner-pulse 1.4s ease-in-out infinite;
}
}
.uploaded {
color: var(--color-success-high);
border-color: var(--color-success-low);
background-color: var(--color-success-low);
}
.link {
color: inherit;
text-decoration: underline;
text-underline-offset: 2px;
&:hover {
color: var(--color-text-high);
}
}
.busy {
color: var(--color-info-high);
border-color: var(--color-info-low);
background-color: var(--color-info-low);
}
.waiting {
color: var(--color-warning-high);
border-color: var(--color-warning-low);
background-color: var(--color-warning-low);
}
.failed {
color: var(--color-error-high);
border-color: var(--color-error-low);
background-color: var(--color-error-low);
}
.action {
display: inline-flex;
align-items: center;
gap: var(--s-1);
margin-inline-start: var(--s-1);
padding: 0 var(--s-1-5);
border: none;
border-radius: var(--radius-full);
background: var(--color-bg-higher);
color: var(--color-text);
font: inherit;
cursor: pointer;
&:hover {
color: var(--color-text-accent);
}
&:focus-visible {
outline: var(--focus-ring);
}
}
@keyframes scanner-pulse {
50% {
opacity: 0.25;
transform: scale(0.8);
}
}
@media (prefers-reduced-motion: reduce) {
.chip .dot {
animation: none;
}
}

View File

@@ -1,156 +0,0 @@
/**
* A match's upload state, one word and an icon at the card's right:
* `uploaded ✓` · `uploading…` · `waiting for result` · `failed [Retry]` ·
* `not uploaded [Upload]` · `skipped: …`.
*/
import clsx from "clsx";
import {
Check,
CloudOff,
CloudUpload,
Hourglass,
TriangleAlert,
} from "lucide-react";
import type { IngestedMatchLink } from "~/features/scanner-ingest/scanner-ingest-schemas";
import { sendouQMatchPage, tournamentMatchPage } from "~/utils/urls";
import { lobbyLabel } from "../core/labels";
import type { IngestSkipReason } from "../core/match-builder";
import type { ScannerLobby } from "../scanner-types";
import type { SendStatus } from "../store/events";
import styles from "./UploadChip.module.css";
export type UploadState =
| { kind: "uploaded"; link?: IngestedMatchLink }
| { kind: "uploading" }
| { kind: "waiting"; onRetry?: () => void }
| { kind: "failed"; error?: string; onRetry?: () => void }
| { kind: "not-uploaded"; onUpload?: () => void }
| { kind: "skipped"; reason: IngestSkipReason; lobby: ScannerLobby | null };
/** Folds a match's aggregated send status, skip reason and the upload toggle into what the chip shows. */
export function uploadStateOf({
send,
skipReason,
lobby,
canUpload,
onUpload,
}: {
send: SendStatus | undefined;
skipReason: IngestSkipReason | undefined;
lobby: ScannerLobby | null;
/** logged in: Retry/Upload buttons show */
canUpload: boolean;
onUpload: () => void;
}): UploadState {
if (skipReason) return { kind: "skipped", reason: skipReason, lobby };
const action = canUpload ? onUpload : undefined;
switch (send?.state) {
case "sent":
return { kind: "uploaded", link: send.link };
case "sending":
return { kind: "uploading" };
case "unlinked":
return { kind: "waiting", onRetry: action };
case "failed":
return { kind: "failed", error: send.error, onRetry: action };
default:
return { kind: "not-uploaded", onUpload: action };
}
}
export function UploadChip({ state }: { state: UploadState }) {
switch (state.kind) {
case "uploaded":
return (
<span className={clsx(styles.chip, styles.uploaded)}>
<Check size={12} aria-hidden />
{state.link ? (
<a
href={linkUrl(state.link)}
target="_blank"
rel="noreferrer"
className={styles.link}
>
uploaded
</a>
) : (
"uploaded"
)}
</span>
);
case "uploading":
return (
<span className={clsx(styles.chip, styles.busy)}>
<span className={styles.dot} />
uploading…
</span>
);
case "waiting":
return (
<span className={clsx(styles.chip, styles.waiting)}>
<Hourglass size={12} aria-hidden />
waiting for result
{state.onRetry ? (
<button
type="button"
className={styles.action}
onClick={state.onRetry}
>
Retry
</button>
) : null}
</span>
);
case "failed":
return (
<span className={clsx(styles.chip, styles.failed)} title={state.error}>
<TriangleAlert size={12} aria-hidden />
failed
{state.onRetry ? (
<button
type="button"
className={styles.action}
onClick={state.onRetry}
>
Retry
</button>
) : null}
</span>
);
case "not-uploaded":
return (
<span className={styles.chip}>
<CloudOff size={12} aria-hidden />
not uploaded
{state.onUpload ? (
<button
type="button"
className={styles.action}
onClick={state.onUpload}
>
<CloudUpload size={12} aria-hidden />
Upload
</button>
) : null}
</span>
);
case "skipped":
return (
<span className={styles.chip}>
skipped:{" "}
{state.reason === "disconnect"
? "disconnect"
: (lobbyLabel(state.lobby) ?? "not a private battle")}
</span>
);
}
}
function linkUrl(link: IngestedMatchLink): string {
return link.type === "tournament"
? tournamentMatchPage({
tournamentId: link.tournamentId,
matchId: link.matchId,
})
: sendouQMatchPage(link.groupMatchId);
}

View File

@@ -0,0 +1,104 @@
/* tone colors win over the card's circle-button color by specificity, hover included */
.trigger {
&[data-tone="success"] {
&,
&:hover {
color: var(--color-success-high);
}
}
&[data-tone="info"] {
&,
&:hover {
color: var(--color-info-high);
}
}
&[data-tone="warning"] {
&,
&:hover {
color: var(--color-warning-high);
}
}
&[data-tone="error"] {
&,
&:hover {
color: var(--color-error-high);
}
}
}
.busy {
animation: scanner-pulse 1.4s ease-in-out infinite;
}
.popover {
width: min(18rem, calc(100vw - 2 * var(--s-4)));
white-space: normal;
}
.body {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: var(--s-2);
padding: var(--s-1);
font-size: var(--font-xs);
}
.title {
display: flex;
align-items: center;
gap: var(--s-1-5);
font-weight: var(--weight-bold);
& svg {
width: 14px;
height: 14px;
flex-shrink: 0;
}
}
.detail {
margin: 0;
font-size: var(--font-2xs);
font-weight: var(--weight-semi);
color: var(--color-text-high);
line-height: 1.5;
}
.error {
margin: 0;
font-size: var(--font-2xs);
color: var(--color-error);
line-height: 1.5;
overflow-wrap: anywhere;
}
.link {
display: inline-flex;
align-items: center;
gap: var(--s-1);
font-size: var(--font-2xs);
font-weight: var(--weight-bold);
color: var(--color-text-accent);
text-decoration: underline;
text-underline-offset: 2px;
}
.action {
align-self: flex-end;
}
@keyframes scanner-pulse {
50% {
opacity: 0.25;
}
}
@media (prefers-reduced-motion: reduce) {
.busy {
animation: none;
}
}

View File

@@ -0,0 +1,202 @@
/**
* A finished match's upload state as one icon button beside the card's
* expand arrow: ✓ uploaded · ☁↑ uploading · ⌛ waiting for result · ⚠ failed
* · ☁⃠ not uploaded (or skipped). Clicking it opens what happened in words,
* the match link once there is one, and Retry / Upload where they apply.
*/
import clsx from "clsx";
import {
Check,
CloudOff,
CloudUpload,
ExternalLink,
Hourglass,
TriangleAlert,
} from "lucide-react";
import type { JSX } from "react";
import { SendouButton } from "~/components/elements/Button";
import { SendouPopover } from "~/components/elements/Popover";
import type { IngestedMatchLink } from "~/features/scanner-ingest/scanner-ingest-schemas";
import { sendouQMatchPage, tournamentMatchPage } from "~/utils/urls";
import { lobbyLabel } from "../core/labels";
import type { IngestSkipReason } from "../core/match-builder";
import type { ScannerLobby } from "../scanner-types";
import type { SendStatus } from "../store/events";
import styles from "./UploadStatus.module.css";
export type UploadState =
| { kind: "uploaded"; link?: IngestedMatchLink }
| { kind: "uploading" }
| { kind: "waiting"; onRetry?: () => void }
| { kind: "failed"; error?: string; onRetry?: () => void }
| { kind: "not-uploaded"; onUpload?: () => void }
| { kind: "skipped"; reason: IngestSkipReason; lobby: ScannerLobby | null };
interface UploadView {
icon: JSX.Element;
tone: "success" | "info" | "warning" | "error" | "muted";
title: string;
detail?: string;
error?: string;
link?: IngestedMatchLink;
action?: { label: string; run: () => void };
}
/** Folds a match's aggregated send status, skip reason and the upload toggle into what the button shows. */
export function uploadStateOf({
send,
skipReason,
lobby,
canUpload,
onUpload,
}: {
send: SendStatus | undefined;
skipReason: IngestSkipReason | undefined;
lobby: ScannerLobby | null;
/** logged in: Retry/Upload buttons show */
canUpload: boolean;
onUpload: () => void;
}): UploadState {
if (skipReason) return { kind: "skipped", reason: skipReason, lobby };
const action = canUpload ? onUpload : undefined;
switch (send?.state) {
case "sent":
return { kind: "uploaded", link: send.link };
case "sending":
return { kind: "uploading" };
case "unlinked":
return { kind: "waiting", onRetry: action };
case "failed":
return { kind: "failed", error: send.error, onRetry: action };
default:
return { kind: "not-uploaded", onUpload: action };
}
}
export function UploadStatusButton({
state,
className,
}: {
state: UploadState;
/** the card's circle button look, shared with the expand arrow */
className?: string;
}) {
const view = viewOf(state);
return (
<SendouPopover
trigger={
<SendouButton
variant="minimal"
size="small"
shape="circle"
icon={view.icon}
className={clsx(className, styles.trigger)}
data-tone={view.tone}
aria-label={view.title}
/>
}
popoverClassName={styles.popover}
placement="bottom end"
>
<div className={styles.body}>
<div className={styles.title}>
{view.icon}
{view.title}
</div>
{view.detail ? <p className={styles.detail}>{view.detail}</p> : null}
{view.error ? <p className={styles.error}>{view.error}</p> : null}
{view.link ? (
<a
href={linkUrl(view.link)}
target="_blank"
rel="noreferrer"
className={styles.link}
>
Open match
<ExternalLink size={12} aria-hidden />
</a>
) : null}
{view.action ? (
<SendouButton
variant="outlined"
size="miniscule"
className={styles.action}
onClick={view.action.run}
>
{view.action.label}
</SendouButton>
) : null}
</div>
</SendouPopover>
);
}
function viewOf(state: UploadState): UploadView {
switch (state.kind) {
case "uploaded":
return {
icon: <Check aria-hidden />,
tone: "success",
title: "Uploaded to sendou.ink",
link: state.link,
};
case "uploading":
return {
icon: <CloudUpload aria-hidden className={styles.busy} />,
tone: "info",
title: "Uploading to sendou.ink…",
};
case "waiting":
return {
icon: <Hourglass aria-hidden />,
tone: "warning",
title: "Waiting for the result",
detail:
"sendou.ink has the game but the match isn't reported yet. It's retried on its own once the match is reported.",
action: retryAction(state.onRetry),
};
case "failed":
return {
icon: <TriangleAlert aria-hidden />,
tone: "error",
title: "Upload failed",
error: state.error,
action: retryAction(state.onRetry),
};
case "not-uploaded":
return {
icon: <CloudOff aria-hidden />,
tone: "muted",
title: "Not uploaded",
detail: state.onUpload
? "This game hasn't been sent to sendou.ink."
: "Log in to upload results to sendou.ink.",
action: state.onUpload
? { label: "Upload", run: state.onUpload }
: undefined,
};
case "skipped":
return {
icon: <CloudOff aria-hidden />,
tone: "muted",
title: "Not uploaded",
detail:
state.reason === "disconnect"
? "A disconnect ended this game before it was decided, so there is no result to upload."
: `Only Private Battle games are uploaded. This one was ${lobbyLabel(state.lobby) ?? "not a private battle"}.`,
};
}
}
function retryAction(onRetry: (() => void) | undefined) {
return onRetry ? { label: "Retry", run: onRetry } : undefined;
}
function linkUrl(link: IngestedMatchLink): string {
return link.type === "tournament"
? tournamentMatchPage({
tournamentId: link.tournamentId,
matchId: link.matchId,
})
: sendouQMatchPage(link.groupMatchId);
}