From bb32c2669419a66342acf6d587a0f95dc03c9ccd Mon Sep 17 00:00:00 2001 From: dahyeon Date: Mon, 13 Jul 2026 21:40:01 -0700 Subject: [PATCH] feat(web): redesign team progress experience --- .../components/competition/TeamSeriesCard.tsx | 138 +++++++ .../competition/TeamTournamentCodes.tsx | 264 +++++++++++++ apps/web/src/pages/MatchTeamProgressPage.tsx | 364 ++++++++++-------- .../web/src/pages/match-team-progress-view.ts | 117 +++++- .../web/test/match-team-progress-view.test.ts | 206 ++++++++++ docs/plans/team-progress-page-ux-refresh.md | 40 +- docs/specs/team-progress-page-ux-refresh.md | 27 +- 7 files changed, 973 insertions(+), 183 deletions(-) create mode 100644 apps/web/src/components/competition/TeamSeriesCard.tsx create mode 100644 apps/web/src/components/competition/TeamTournamentCodes.tsx diff --git a/apps/web/src/components/competition/TeamSeriesCard.tsx b/apps/web/src/components/competition/TeamSeriesCard.tsx new file mode 100644 index 00000000..8b7794d1 --- /dev/null +++ b/apps/web/src/components/competition/TeamSeriesCard.tsx @@ -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 = { + 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; + highlightedTeamId: TeamId; + emphasized?: boolean; + children?: ReactNode; +}) { + const presentation = getTeamSeriesPresentation(series); + const headingId = `team-series-${String(series.seriesId)}`; + + return ( +
+
+
+

+ {displayLabel} +

+
+ {series.code && ( + {series.code} + )} + {seriesRuleLabel(series)} +
+
+ + {presentation.label} + +
+ +
    + {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 ( +
  • +
    + + {entry.slot} 슬롯: + {teamName} + + {isHighlightedTeam && ( + + 이 팀 + + )} + {isWinner && ( + + 승리 + + )} +
    + + + {presentation.showScore ? "게임 승수: " : "점수 없음"} + + {presentation.showScore ? ( + entry.gameWins + ) : ( + + )} + +
  • + ); + })} +
+ + {children} +
+ ); +} + +function seriesRuleLabel(series: SeriesProjection): string { + if (series.rule.type === "fixed-games") { + return `${series.rule.gameCount}게임`; + } + return `${series.rule.maxGames}전 ${series.rule.winsRequired}선승`; +} diff --git a/apps/web/src/components/competition/TeamTournamentCodes.tsx b/apps/web/src/components/competition/TeamTournamentCodes.tsx new file mode 100644 index 00000000..cdaa28d0 --- /dev/null +++ b/apps/web/src/components/competition/TeamTournamentCodes.tsx @@ -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 = { + 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(null); + const [feedback, setFeedback] = useState(null); + const [now, setNow] = useState(() => Date.now()); + const clearFeedbackTimeoutRef = useRef(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 ( +
+

+ 이 경기에 배정된 토너먼트 코드가 없습니다. +

+
+ ); + } + + 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 ( +
+
+

게임 코드

+

+ 세트에 맞는 코드를 복사해 클라이언트에 입력하세요. +

+
+
    + {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 ( +
  1. +
    +

    + {assignment.ordinal}세트 +

    +

    + 전체 Game {assignment.displayNumber} +

    +
    + +
    + {assignment.code ? ( + + ) : ( +

    + 발급 대기 중 +

    + )} + {assignment.code && + assignment.state === "reserved" && + assignment.expiresAt && ( +

    + +

    + )} +
    + +
    + + {presentation.label} + + {assignment.code && assignment.state === "reserved" && ( + + )} +
    +
  2. + ); + })} +
+ + {feedback && ( +

+ {feedback.message} +

+ )} +
+ ); +} + +function readCurrentTime(): number { + return Date.now(); +} + +function AutoSizingCodeField({ + label, + value, +}: { + label: string; + value: string; +}) { + const fieldRef = useRef(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 ( +