feat(web): redesign team progress experience
This commit is contained in:
1 parent
81b951889f
commit
bb32c26694
7 files changed
+973
-183
No files matched your search
@@ -0,0 +1,138 @@
|
||||
import type {
|
||||
CompetitionTeamView,
|
||||
SeriesProjection,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import type { ReactNode } from "react";
|
||||
import {
|
||||
getTeamSeriesPresentation,
|
||||
type TeamSeriesTone,
|
||||
} from "../../pages/match-team-progress-view";
|
||||
import { isSeriesEntryWinner } from "./series-score-card-model";
|
||||
|
||||
const STATUS_TONE_CLASS: Record<TeamSeriesTone, string> = {
|
||||
muted: "border-base-content/15 bg-base-200 text-base-content",
|
||||
ready: "border-primary/50 bg-primary/10 text-base-content",
|
||||
live: "border-info/60 bg-info/10 text-base-content",
|
||||
completed: "border-base-content/20 bg-base-200 text-base-content",
|
||||
adjudicated: "border-warning/60 bg-warning/15 text-base-content",
|
||||
};
|
||||
|
||||
export function TeamSeriesCard({
|
||||
series,
|
||||
displayLabel,
|
||||
teamById,
|
||||
highlightedTeamId,
|
||||
emphasized = false,
|
||||
children,
|
||||
}: {
|
||||
series: SeriesProjection;
|
||||
displayLabel: string;
|
||||
teamById: ReadonlyMap<TeamId, CompetitionTeamView>;
|
||||
highlightedTeamId: TeamId;
|
||||
emphasized?: boolean;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
const presentation = getTeamSeriesPresentation(series);
|
||||
const headingId = `team-series-${String(series.seriesId)}`;
|
||||
|
||||
return (
|
||||
<article
|
||||
className={`overflow-hidden border bg-base-100 ${
|
||||
emphasized ? "border-primary/30" : "border-base-content/10"
|
||||
}`}
|
||||
aria-labelledby={headingId}
|
||||
>
|
||||
<header
|
||||
className={`flex flex-wrap items-start justify-between gap-3 border-b px-4 py-3 sm:px-5 ${
|
||||
emphasized
|
||||
? "border-primary/20 bg-primary/[0.035]"
|
||||
: "border-base-content/10 bg-base-200/40"
|
||||
}`}
|
||||
>
|
||||
<div className="min-w-0">
|
||||
<h3
|
||||
id={headingId}
|
||||
className="break-words text-base font-black text-base-content"
|
||||
>
|
||||
{displayLabel}
|
||||
</h3>
|
||||
<div className="mt-1 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-content-muted">
|
||||
{series.code && (
|
||||
<code className="break-all font-mono">{series.code}</code>
|
||||
)}
|
||||
<span>{seriesRuleLabel(series)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<span
|
||||
className={`shrink-0 border-l-2 px-2 py-1 text-xs font-bold ${STATUS_TONE_CLASS[presentation.tone]}`}
|
||||
>
|
||||
{presentation.label}
|
||||
</span>
|
||||
</header>
|
||||
|
||||
<ul
|
||||
className="divide-y divide-base-content/10"
|
||||
aria-label={`${displayLabel} 대진`}
|
||||
>
|
||||
{series.entries.map((entry) => {
|
||||
const team = entry.teamId ? teamById.get(entry.teamId) : undefined;
|
||||
const teamName =
|
||||
team?.name ?? (entry.teamId ? "알 수 없는 팀" : "상대 결정 대기");
|
||||
const isHighlightedTeam = entry.teamId === highlightedTeamId;
|
||||
const isWinner = isSeriesEntryWinner(series, entry.teamId);
|
||||
return (
|
||||
<li
|
||||
key={entry.slot}
|
||||
className={`grid min-h-12 grid-cols-[minmax(0,1fr)_3rem] items-center gap-3 px-4 py-2.5 sm:px-5 ${
|
||||
isHighlightedTeam ? "bg-base-200/35" : ""
|
||||
}`}
|
||||
>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span
|
||||
className={`min-w-0 break-words text-sm ${
|
||||
isWinner || isHighlightedTeam
|
||||
? "font-bold text-base-content"
|
||||
: "text-content-subtle"
|
||||
}`}
|
||||
>
|
||||
<span className="sr-only">{entry.slot} 슬롯: </span>
|
||||
{teamName}
|
||||
</span>
|
||||
{isHighlightedTeam && (
|
||||
<span className="border border-base-content/15 bg-base-100 px-1.5 py-0.5 text-[11px] font-bold text-base-content">
|
||||
이 팀
|
||||
</span>
|
||||
)}
|
||||
{isWinner && (
|
||||
<span className="border-l-2 border-success bg-success/10 px-1.5 py-0.5 text-[11px] font-bold text-base-content">
|
||||
승리
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-right font-mono text-base font-bold tabular-nums text-base-content">
|
||||
<span className="sr-only">
|
||||
{presentation.showScore ? "게임 승수: " : "점수 없음"}
|
||||
</span>
|
||||
{presentation.showScore ? (
|
||||
entry.gameWins
|
||||
) : (
|
||||
<span aria-hidden="true">—</span>
|
||||
)}
|
||||
</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
|
||||
{children}
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
function seriesRuleLabel(series: SeriesProjection): string {
|
||||
if (series.rule.type === "fixed-games") {
|
||||
return `${series.rule.gameCount}게임`;
|
||||
}
|
||||
return `${series.rule.maxGames}전 ${series.rule.winsRequired}선승`;
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
import type { TeamTournamentCodeView } from "@lolympus/contracts";
|
||||
import { Check, Copy, LoaderCircle } from "lucide-react";
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import {
|
||||
copyTournamentCode,
|
||||
getNextTournamentCodeExpiryDelay,
|
||||
getTournamentCodeCopyLabel,
|
||||
getTournamentCodeExpiryLabel,
|
||||
getTournamentCodePresentation,
|
||||
type TournamentCodeCopyFeedback,
|
||||
type TournamentCodeTone,
|
||||
} from "../../pages/match-team-progress-view";
|
||||
|
||||
const CODE_TONE_CLASS: Record<TournamentCodeTone, string> = {
|
||||
pending: "border-base-content/15 bg-base-200 text-base-content",
|
||||
available: "border-primary/50 bg-primary/10 text-base-content",
|
||||
expired: "border-error/50 bg-error/10 text-base-content",
|
||||
used: "border-base-content/20 bg-base-200 text-base-content",
|
||||
};
|
||||
|
||||
type VisibleFeedback = TournamentCodeCopyFeedback & { gameSlotId: string };
|
||||
|
||||
export function TeamTournamentCodes({
|
||||
assignments,
|
||||
seriesLabel,
|
||||
}: {
|
||||
assignments: readonly TeamTournamentCodeView[];
|
||||
seriesLabel: string;
|
||||
}) {
|
||||
const [copyingSlotId, setCopyingSlotId] = useState<string | null>(null);
|
||||
const [feedback, setFeedback] = useState<VisibleFeedback | null>(null);
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
const clearFeedbackTimeoutRef = useRef<number | null>(null);
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
if (clearFeedbackTimeoutRef.current !== null) {
|
||||
window.clearTimeout(clearFeedbackTimeoutRef.current);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const delay = getNextTournamentCodeExpiryDelay(assignments, now);
|
||||
if (delay === null) return;
|
||||
const timeoutId = window.setTimeout(
|
||||
() => setNow(Date.now()),
|
||||
Math.max(1, delay),
|
||||
);
|
||||
return () => window.clearTimeout(timeoutId);
|
||||
}, [assignments, now]);
|
||||
|
||||
if (assignments.length === 0) {
|
||||
return (
|
||||
<div className="border-t border-base-content/10 px-4 py-5 sm:px-5">
|
||||
<p role="status" className="text-sm text-content-muted">
|
||||
이 경기에 배정된 토너먼트 코드가 없습니다.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
async function handleCopy(assignment: TeamTournamentCodeView) {
|
||||
if (!assignment.code || copyingSlotId !== null) return;
|
||||
if (clearFeedbackTimeoutRef.current !== null) {
|
||||
window.clearTimeout(clearFeedbackTimeoutRef.current);
|
||||
clearFeedbackTimeoutRef.current = null;
|
||||
}
|
||||
|
||||
const slotId = String(assignment.gameSlotId);
|
||||
const gameLabel = `${seriesLabel} ${assignment.ordinal}세트`;
|
||||
const currentTime = readCurrentTime();
|
||||
setNow(currentTime);
|
||||
if (!getTournamentCodePresentation(assignment, currentTime).canCopy) {
|
||||
setFeedback({
|
||||
kind: "error",
|
||||
gameSlotId: slotId,
|
||||
message: `${gameLabel} 코드는 만료되었거나 사용할 수 없어 복사하지 않았습니다.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
setCopyingSlotId(slotId);
|
||||
setFeedback(null);
|
||||
const clipboard = navigator.clipboard;
|
||||
const result = await copyTournamentCode(
|
||||
clipboard?.writeText ? clipboard.writeText.bind(clipboard) : undefined,
|
||||
assignment.code,
|
||||
gameLabel,
|
||||
);
|
||||
setCopyingSlotId(null);
|
||||
setFeedback({ ...result, gameSlotId: slotId });
|
||||
|
||||
if (result.kind === "success") {
|
||||
clearFeedbackTimeoutRef.current = window.setTimeout(() => {
|
||||
setFeedback(null);
|
||||
clearFeedbackTimeoutRef.current = null;
|
||||
}, 2500);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section
|
||||
className="border-t border-base-content/10"
|
||||
aria-label={`${seriesLabel} 토너먼트 코드`}
|
||||
>
|
||||
<div className="flex flex-wrap items-baseline justify-between gap-2 bg-base-200/25 px-4 py-2.5 sm:px-5">
|
||||
<h4 className="text-sm font-bold text-base-content">게임 코드</h4>
|
||||
<p className="text-xs text-content-muted">
|
||||
세트에 맞는 코드를 복사해 클라이언트에 입력하세요.
|
||||
</p>
|
||||
</div>
|
||||
<ol className="divide-y divide-base-content/10">
|
||||
{assignments.map((assignment) => {
|
||||
const slotId = String(assignment.gameSlotId);
|
||||
const presentation = getTournamentCodePresentation(assignment, now);
|
||||
const isCopying = copyingSlotId === slotId;
|
||||
const copied =
|
||||
feedback?.kind === "success" && feedback.gameSlotId === slotId;
|
||||
return (
|
||||
<li
|
||||
key={slotId}
|
||||
className="grid gap-3 px-4 py-3 sm:px-5 md:grid-cols-[5.5rem_minmax(0,1fr)_auto] md:items-center"
|
||||
>
|
||||
<div>
|
||||
<p className="text-sm font-bold text-base-content">
|
||||
{assignment.ordinal}세트
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs text-content-muted">
|
||||
전체 Game {assignment.displayNumber}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="min-w-0">
|
||||
{assignment.code ? (
|
||||
<AutoSizingCodeField
|
||||
label={`${seriesLabel} ${assignment.ordinal}세트 토너먼트 코드`}
|
||||
value={assignment.code}
|
||||
/>
|
||||
) : (
|
||||
<p className="text-sm font-bold text-content-muted">
|
||||
발급 대기 중
|
||||
</p>
|
||||
)}
|
||||
{assignment.code &&
|
||||
assignment.state === "reserved" &&
|
||||
assignment.expiresAt && (
|
||||
<p className="mt-1 text-xs text-content-muted">
|
||||
<time dateTime={assignment.expiresAt}>
|
||||
{getTournamentCodeExpiryLabel(
|
||||
assignment.expiresAt,
|
||||
now,
|
||||
)}
|
||||
</time>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-2 md:justify-end">
|
||||
<span
|
||||
className={`border-l-2 px-2 py-1 text-xs font-bold ${CODE_TONE_CLASS[presentation.tone]}`}
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
aria-atomic="true"
|
||||
>
|
||||
{presentation.label}
|
||||
</span>
|
||||
{assignment.code && assignment.state === "reserved" && (
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex min-h-11 items-center justify-center gap-1.5 border border-base-content/20 bg-base-100 px-3 text-sm font-bold text-base-content hover:border-primary/50 hover:bg-primary/5 focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-not-allowed disabled:opacity-70"
|
||||
aria-label={
|
||||
presentation.canCopy
|
||||
? getTournamentCodeCopyLabel(assignment, seriesLabel)
|
||||
: `${seriesLabel} ${assignment.ordinal}세트 토너먼트 코드 만료됨`
|
||||
}
|
||||
disabled={!presentation.canCopy || copyingSlotId !== null}
|
||||
onClick={() => void handleCopy(assignment)}
|
||||
>
|
||||
{!presentation.canCopy ? null : isCopying ? (
|
||||
<LoaderCircle
|
||||
className="h-4 w-4 animate-spin motion-reduce:animate-none"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : copied ? (
|
||||
<Check className="h-4 w-4" aria-hidden="true" />
|
||||
) : (
|
||||
<Copy className="h-4 w-4" aria-hidden="true" />
|
||||
)}
|
||||
{!presentation.canCopy
|
||||
? "복사 불가"
|
||||
: isCopying
|
||||
? "복사 중"
|
||||
: copied
|
||||
? "복사됨"
|
||||
: "복사"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ol>
|
||||
|
||||
{feedback && (
|
||||
<p
|
||||
className={`border-t px-4 py-2.5 text-sm sm:px-5 ${
|
||||
feedback.kind === "error"
|
||||
? "border-error/30 bg-error/10 text-base-content"
|
||||
: "border-success/30 bg-success/10 text-base-content"
|
||||
}`}
|
||||
role={feedback.kind === "error" ? "alert" : "status"}
|
||||
aria-live={feedback.kind === "error" ? "assertive" : "polite"}
|
||||
aria-atomic="true"
|
||||
>
|
||||
{feedback.message}
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function readCurrentTime(): number {
|
||||
return Date.now();
|
||||
}
|
||||
|
||||
function AutoSizingCodeField({
|
||||
label,
|
||||
value,
|
||||
}: {
|
||||
label: string;
|
||||
value: string;
|
||||
}) {
|
||||
const fieldRef = useRef<HTMLTextAreaElement>(null);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const resizeToContent = () => {
|
||||
const field = fieldRef.current;
|
||||
if (!field) return;
|
||||
field.style.height = "auto";
|
||||
const borderHeight = field.offsetHeight - field.clientHeight;
|
||||
field.style.height = `${field.scrollHeight + borderHeight}px`;
|
||||
};
|
||||
|
||||
resizeToContent();
|
||||
window.addEventListener("resize", resizeToContent);
|
||||
return () => window.removeEventListener("resize", resizeToContent);
|
||||
}, [value]);
|
||||
|
||||
return (
|
||||
<textarea
|
||||
ref={fieldRef}
|
||||
aria-label={label}
|
||||
className="block min-h-11 w-full resize-none overflow-hidden border border-base-content/15 bg-base-100 px-3 py-2 font-mono text-sm font-bold leading-5 text-base-content focus-visible:ring-2 focus-visible:ring-primary"
|
||||
onClick={(event) => event.currentTarget.select()}
|
||||
onFocus={(event) => event.currentTarget.select()}
|
||||
readOnly
|
||||
rows={1}
|
||||
spellCheck={false}
|
||||
value={value}
|
||||
wrap="soft"
|
||||
/>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user