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
@@ -1,15 +1,27 @@
|
||||
import type { CompetitionDetailResponse } from "@lolympus/contracts";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type {
|
||||
CompetitionDetailResponse,
|
||||
SeriesProjection,
|
||||
} from "@lolympus/contracts";
|
||||
import { ArrowLeft, ChevronDown, UsersRound } from "lucide-react";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { Link, useParams, useSearchParams } from "react-router";
|
||||
import { useCompetition, useTeamCompetition } from "../api/hooks";
|
||||
import { SeriesScoreCard } from "../components/competition/SeriesScoreCard";
|
||||
import { TeamSeriesCard } from "../components/competition/TeamSeriesCard";
|
||||
import { TeamTournamentCodes } from "../components/competition/TeamTournamentCodes";
|
||||
import { DEFAULT_COMMUNITY_ID } from "../config";
|
||||
import { positionLabel } from "../lib/league";
|
||||
import {
|
||||
getTeamProgressErrorContent,
|
||||
isConsistentTeamProgressSnapshot,
|
||||
shouldOfferTeamSelection,
|
||||
type TeamProgressErrorContent,
|
||||
} from "./match-team-progress-state";
|
||||
import {
|
||||
createTeamSeriesGroups,
|
||||
getTeamSeriesDisplayLabel,
|
||||
sortCompletedTeamSeries,
|
||||
sortTeamMembersForRoster,
|
||||
} from "./match-team-progress-view";
|
||||
|
||||
export default function MatchTeamProgressPage() {
|
||||
const { id } = useParams();
|
||||
@@ -24,10 +36,11 @@ export default function MatchTeamProgressPage() {
|
||||
);
|
||||
const refetchCompetition = competitionQuery.refetch;
|
||||
const refetchTeam = teamQuery.refetch;
|
||||
const [copiedSlotId, setCopiedSlotId] = useState<string | null>(null);
|
||||
const lastAutoRefetchedMismatchRef = useRef<string | null>(null);
|
||||
const contentHeadingRef = useRef<HTMLHeadingElement>(null);
|
||||
const competition = competitionQuery.data;
|
||||
const teamView = teamQuery.data;
|
||||
const teamViewId = teamView?.teamId;
|
||||
const hasQueryError = Boolean(
|
||||
competitionQuery.error || teamQuery.error,
|
||||
);
|
||||
@@ -66,6 +79,11 @@ export default function MatchTeamProgressPage() {
|
||||
revisionMismatchKey,
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isSelectingTeam || !teamViewId || !revisionsMatch) return;
|
||||
contentHeadingRef.current?.focus({ preventScroll: true });
|
||||
}, [isSelectingTeam, revisionsMatch, teamViewId]);
|
||||
|
||||
function retryBoth() {
|
||||
void Promise.all([refetchCompetition(), refetchTeam()]).catch(
|
||||
() => undefined,
|
||||
@@ -136,179 +154,191 @@ export default function MatchTeamProgressPage() {
|
||||
competition.teams.map((team) => [team.teamId, team]),
|
||||
);
|
||||
const team = teamById.get(teamView.teamId);
|
||||
const completedSeries = competition.projection.series.filter(
|
||||
(series) =>
|
||||
series.status === "completed" &&
|
||||
series.entries.some((entry) => entry.teamId === teamView.teamId),
|
||||
const activeSeriesGroups = createTeamSeriesGroups(
|
||||
teamView.activeSeries,
|
||||
teamView.tournamentCodes,
|
||||
);
|
||||
|
||||
async function copyCode(gameSlotId: string, code: string | null) {
|
||||
if (!code) return;
|
||||
try {
|
||||
await navigator.clipboard.writeText(code);
|
||||
setCopiedSlotId(gameSlotId);
|
||||
window.setTimeout(() => setCopiedSlotId(null), 1500);
|
||||
} catch {
|
||||
setCopiedSlotId(null);
|
||||
}
|
||||
}
|
||||
const completedSeries = sortCompletedTeamSeries(
|
||||
competition.projection.series.filter(
|
||||
(
|
||||
series,
|
||||
): series is Extract<SeriesProjection, { status: "completed" }> =>
|
||||
series.status === "completed" &&
|
||||
series.entries.some((entry) => entry.teamId === teamView.teamId),
|
||||
),
|
||||
);
|
||||
const recentSeries = completedSeries.slice(0, 2);
|
||||
const olderSeries = completedSeries.slice(2);
|
||||
const rounds = competition.projection.rounds;
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-6 sm:px-6">
|
||||
<Link
|
||||
to={`/match/${id}`}
|
||||
className="mb-5 inline-flex text-xs text-base-content/40 hover:text-base-content"
|
||||
className="mb-5 inline-flex min-h-11 items-center gap-1.5 text-sm font-bold text-content-muted hover:text-base-content focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
← 내전 상세로
|
||||
<ArrowLeft className="h-4 w-4" aria-hidden="true" />
|
||||
내전 상세로
|
||||
</Link>
|
||||
|
||||
<header className="mb-6 border-b border-base-content/10 pb-5">
|
||||
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
{selectedTeamId ? "Team Competition" : "My Competition"}
|
||||
</p>
|
||||
<h1 className="mt-1 text-2xl font-black">
|
||||
{team?.name ?? (selectedTeamId ? "팀" : "내 팀")}
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-base-content/45">
|
||||
해당 팀의 공식 대진과 토너먼트 코드가 표시됩니다.
|
||||
</p>
|
||||
<header className="mb-8 flex flex-col gap-4 border-b border-base-content/10 pb-6 sm:flex-row sm:items-end sm:justify-between">
|
||||
<div className="min-w-0">
|
||||
<p className="text-xs font-bold text-content-muted">팀 경기 현황</p>
|
||||
<h1
|
||||
ref={contentHeadingRef}
|
||||
className="mt-1 min-w-0 break-words text-2xl font-black sm:text-3xl"
|
||||
tabIndex={-1}
|
||||
>
|
||||
{team?.name ?? (selectedTeamId ? "팀" : "내 팀")}
|
||||
</h1>
|
||||
<p className="mt-2 max-w-2xl text-sm text-content-muted">
|
||||
다음 상대와 세트별 토너먼트 코드를 한곳에서 확인할 수 있습니다.
|
||||
</p>
|
||||
</div>
|
||||
<Link
|
||||
to={`/match/${id}/team?select=1`}
|
||||
className="mt-2 inline-flex text-xs text-base-content/40 hover:text-primary"
|
||||
className="inline-flex min-h-11 shrink-0 items-center justify-center gap-2 border border-base-content/20 bg-base-100 px-3 text-sm font-bold text-base-content hover:border-primary/40 hover:bg-primary/5 focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
다른 팀 보기
|
||||
<UsersRound className="h-4 w-4" aria-hidden="true" />
|
||||
팀 변경
|
||||
</Link>
|
||||
</header>
|
||||
|
||||
<section className="mb-6" aria-labelledby="active-series-heading">
|
||||
<h2
|
||||
<section className="mb-8" aria-labelledby="active-series-heading">
|
||||
<SectionHeading
|
||||
id="active-series-heading"
|
||||
className="mb-3 text-xs font-bold uppercase tracking-wider text-base-content/40"
|
||||
>
|
||||
진행할 Series
|
||||
</h2>
|
||||
{teamView.activeSeries.length > 0 ? (
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{teamView.activeSeries.map((series) => (
|
||||
<SeriesScoreCard
|
||||
key={series.seriesId}
|
||||
series={series}
|
||||
teamById={teamById}
|
||||
/>
|
||||
))}
|
||||
title="다음 경기"
|
||||
description="현재 팀이 준비하거나 진행해야 하는 공식 대진입니다."
|
||||
/>
|
||||
{activeSeriesGroups.length > 0 ? (
|
||||
<div className="space-y-4">
|
||||
{activeSeriesGroups.map(({ series, codes }) => {
|
||||
const displayLabel = getTeamSeriesDisplayLabel(series, rounds);
|
||||
return (
|
||||
<TeamSeriesCard
|
||||
key={series.seriesId}
|
||||
series={series}
|
||||
displayLabel={displayLabel}
|
||||
teamById={teamById}
|
||||
highlightedTeamId={teamView.teamId}
|
||||
emphasized
|
||||
>
|
||||
<TeamTournamentCodes
|
||||
assignments={codes}
|
||||
seriesLabel={displayLabel}
|
||||
/>
|
||||
</TeamSeriesCard>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
) : (
|
||||
<EmptyState message="현재 진행할 대진이 없습니다." />
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="mb-6" aria-labelledby="codes-heading">
|
||||
<h2
|
||||
id="codes-heading"
|
||||
className="mb-3 text-xs font-bold uppercase tracking-wider text-base-content/40"
|
||||
>
|
||||
토너먼트 코드
|
||||
</h2>
|
||||
{teamView.tournamentCodes.length > 0 ? (
|
||||
<ul className="grid gap-3 sm:grid-cols-2">
|
||||
{teamView.tournamentCodes.map((assignment) => (
|
||||
<li
|
||||
key={assignment.gameSlotId}
|
||||
className="border border-base-content/10 bg-base-100 p-4"
|
||||
>
|
||||
<div className="flex items-center justify-between gap-3">
|
||||
<span className="text-xs font-bold text-base-content/45">
|
||||
Game {assignment.displayNumber}
|
||||
</span>
|
||||
<span className="text-[11px] text-base-content/35">
|
||||
{assignment.state === "used"
|
||||
? "사용됨"
|
||||
: assignment.state === "reserved"
|
||||
? "사용 가능"
|
||||
: "발급 대기"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-3 flex items-center gap-2">
|
||||
<code className="min-w-0 flex-1 truncate font-mono text-sm font-bold text-primary">
|
||||
{assignment.code ?? "발급 대기"}
|
||||
</code>
|
||||
{assignment.code && assignment.state !== "used" && (
|
||||
<button
|
||||
type="button"
|
||||
className="border border-base-content/10 px-2 py-1 text-xs font-bold hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
||||
onClick={() =>
|
||||
void copyCode(assignment.gameSlotId, assignment.code)
|
||||
}
|
||||
>
|
||||
{copiedSlotId === assignment.gameSlotId
|
||||
? "복사됨"
|
||||
: "복사"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
) : (
|
||||
<EmptyState message="배정된 토너먼트 코드가 없습니다." />
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="mb-6" aria-labelledby="completed-heading">
|
||||
<h2
|
||||
id="completed-heading"
|
||||
className="mb-3 text-xs font-bold uppercase tracking-wider text-base-content/40"
|
||||
>
|
||||
종료된 Series
|
||||
</h2>
|
||||
{completedSeries.length > 0 ? (
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{completedSeries.map((series) => (
|
||||
<SeriesScoreCard
|
||||
key={series.seriesId}
|
||||
series={series}
|
||||
teamById={teamById}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
<EmptyState message="아직 종료된 대진이 없습니다." />
|
||||
<EmptyState message="현재 준비하거나 진행할 대진이 없습니다." />
|
||||
)}
|
||||
</section>
|
||||
|
||||
{team && (
|
||||
<section className="border border-base-content/10 bg-base-100">
|
||||
<h2 className="border-b border-base-content/10 bg-base-200/40 px-4 py-2 text-xs font-bold uppercase tracking-wider text-base-content/40">
|
||||
팀 구성
|
||||
</h2>
|
||||
<ul className="divide-y divide-base-content/8">
|
||||
{team.members.map((member) => (
|
||||
<section className="mb-8" aria-labelledby="roster-heading">
|
||||
<SectionHeading
|
||||
id="roster-heading"
|
||||
title="팀 구성"
|
||||
description={`${team.members.length}명의 라인업을 포지션 순서로 보여줍니다.`}
|
||||
/>
|
||||
<ul className="divide-y divide-base-content/10 border border-base-content/10 bg-base-100">
|
||||
{sortTeamMembersForRoster(team.members).map((member) => (
|
||||
<li
|
||||
key={member.userId}
|
||||
className="flex items-center gap-3 px-4 py-3"
|
||||
className="grid min-h-12 grid-cols-[4.5rem_minmax(0,1fr)] items-center gap-3 px-4 py-2 sm:px-5"
|
||||
>
|
||||
<div className="min-w-0 flex-1">
|
||||
<p className="truncate text-sm font-bold">
|
||||
<span className="text-xs font-bold text-content-muted">
|
||||
{member.assignedPosition
|
||||
? positionLabel[member.assignedPosition]
|
||||
: "미정"}
|
||||
</span>
|
||||
<div className="flex min-w-0 flex-wrap items-center gap-2">
|
||||
<span className="min-w-0 break-words text-sm font-bold text-base-content">
|
||||
{member.displayName}
|
||||
</p>
|
||||
{member.assignedPosition && (
|
||||
<p className="mt-0.5 text-xs text-base-content/35">
|
||||
{member.assignedPosition}
|
||||
</p>
|
||||
</span>
|
||||
{member.userId === team.captainUserId && (
|
||||
<span className="border-l-2 border-warning bg-warning/15 px-1.5 py-0.5 text-[11px] font-bold text-base-content">
|
||||
팀장
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{member.userId === team.captainUserId && (
|
||||
<span className="text-xs font-bold text-warning">팀장</span>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<section className="mb-6" aria-labelledby="completed-heading">
|
||||
<SectionHeading
|
||||
id="completed-heading"
|
||||
title="지난 경기"
|
||||
description="최근 결과를 먼저 보여주며, 오래된 결과는 펼쳐서 확인할 수 있습니다."
|
||||
/>
|
||||
{completedSeries.length > 0 ? (
|
||||
<>
|
||||
<div className="grid gap-3 md:grid-cols-2">
|
||||
{recentSeries.map((series) => (
|
||||
<TeamSeriesCard
|
||||
key={series.seriesId}
|
||||
series={series}
|
||||
displayLabel={getTeamSeriesDisplayLabel(series, rounds)}
|
||||
teamById={teamById}
|
||||
highlightedTeamId={teamView.teamId}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
{olderSeries.length > 0 && (
|
||||
<details className="group mt-3 border border-base-content/10 bg-base-100">
|
||||
<summary className="flex min-h-11 cursor-pointer list-none items-center justify-between gap-3 px-4 text-sm font-bold text-base-content hover:bg-base-200/50 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary [&::-webkit-details-marker]:hidden">
|
||||
<span>이전 경기 {olderSeries.length}개 더 보기</span>
|
||||
<ChevronDown
|
||||
className="h-4 w-4 transition-transform group-open:rotate-180 motion-reduce:transition-none"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</summary>
|
||||
<div className="grid gap-3 border-t border-base-content/10 p-3 md:grid-cols-2">
|
||||
{olderSeries.map((series) => (
|
||||
<TeamSeriesCard
|
||||
key={series.seriesId}
|
||||
series={series}
|
||||
displayLabel={getTeamSeriesDisplayLabel(series, rounds)}
|
||||
teamById={teamById}
|
||||
highlightedTeamId={teamView.teamId}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</details>
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
<EmptyState message="아직 종료된 대진이 없습니다." />
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function SectionHeading({
|
||||
id,
|
||||
title,
|
||||
description,
|
||||
}: {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
}) {
|
||||
return (
|
||||
<div className="mb-3 border-b border-base-content/10 pb-2">
|
||||
<h2 id={id} className="text-base font-black text-base-content">
|
||||
{title}
|
||||
</h2>
|
||||
<p className="mt-0.5 text-xs text-content-muted">{description}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TeamSelectionState({
|
||||
competition,
|
||||
matchId,
|
||||
@@ -316,21 +346,28 @@ function TeamSelectionState({
|
||||
competition: CompetitionDetailResponse;
|
||||
matchId: string | undefined;
|
||||
}) {
|
||||
const headingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
headingRef.current?.focus({ preventScroll: true });
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-6 sm:px-6">
|
||||
<Link
|
||||
to={`/match/${matchId}`}
|
||||
className="mb-5 inline-flex text-xs text-base-content/40 hover:text-base-content"
|
||||
className="mb-5 inline-flex min-h-11 items-center gap-1.5 text-sm font-bold text-content-muted hover:text-base-content focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
← 내전 상세로
|
||||
<ArrowLeft className="h-4 w-4" aria-hidden="true" />
|
||||
내전 상세로
|
||||
</Link>
|
||||
|
||||
<header className="mb-6 border-b border-base-content/10 pb-5">
|
||||
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
||||
Team Competition
|
||||
</p>
|
||||
<h1 className="mt-1 text-2xl font-black">팀 선택</h1>
|
||||
<p className="mt-1 text-sm text-base-content/45">
|
||||
<p className="text-xs font-bold text-content-muted">팀 경기 현황</p>
|
||||
<h1 ref={headingRef} className="mt-1 text-2xl font-black" tabIndex={-1}>
|
||||
팀 선택
|
||||
</h1>
|
||||
<p className="mt-1 text-sm text-content-muted">
|
||||
진행 상황과 토너먼트 코드를 확인할 팀을 선택해 주세요.
|
||||
</p>
|
||||
</header>
|
||||
@@ -341,12 +378,12 @@ function TeamSelectionState({
|
||||
<li key={team.teamId}>
|
||||
<Link
|
||||
to={`/match/${matchId}/team?teamId=${team.teamId}`}
|
||||
className="flex items-center justify-between gap-3 border border-base-content/10 bg-base-100 px-4 py-4 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
||||
className="flex min-h-12 items-center justify-between gap-3 border border-base-content/10 bg-base-100 px-4 py-3 text-base-content hover:border-primary/40 hover:bg-primary/5 focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
<span className="min-w-0 truncate text-sm font-bold">
|
||||
<span className="min-w-0 break-words text-sm font-bold">
|
||||
{team.name}
|
||||
</span>
|
||||
<span className="shrink-0 text-xs text-base-content/35">
|
||||
<span className="shrink-0 text-xs text-content-muted">
|
||||
{team.members.length}명
|
||||
</span>
|
||||
</Link>
|
||||
@@ -366,9 +403,11 @@ function TeamProgressLoadingState() {
|
||||
className="mx-auto max-w-5xl space-y-3 px-4 py-12 sm:px-6"
|
||||
aria-busy="true"
|
||||
aria-label="팀 진행 정보를 불러오는 중"
|
||||
role="status"
|
||||
>
|
||||
<div className="h-7 w-48 animate-pulse bg-base-200" />
|
||||
<div className="h-32 animate-pulse bg-base-200/70" />
|
||||
<span className="sr-only">팀 진행 정보를 불러오는 중입니다.</span>
|
||||
<div className="h-7 w-48 animate-pulse bg-base-200 motion-reduce:animate-none" />
|
||||
<div className="h-32 animate-pulse bg-base-200/70 motion-reduce:animate-none" />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -384,6 +423,12 @@ function TeamProgressProblemState({
|
||||
matchId: string | undefined;
|
||||
onRetry: () => void;
|
||||
}) {
|
||||
const headingRef = useRef<HTMLHeadingElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
headingRef.current?.focus({ preventScroll: true });
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<main className="mx-auto max-w-5xl px-4 py-20 sm:px-6">
|
||||
<section
|
||||
@@ -391,20 +436,25 @@ function TeamProgressProblemState({
|
||||
aria-busy={isRetrying}
|
||||
className="border border-base-content/10 bg-base-100 px-5 py-8 text-center"
|
||||
>
|
||||
<h1 className="text-lg font-bold">{content.title}</h1>
|
||||
<p className="mt-2 text-sm text-base-content/45">
|
||||
<h1 ref={headingRef} className="text-lg font-bold" tabIndex={-1}>
|
||||
{content.title}
|
||||
</h1>
|
||||
<p className="mt-2 text-sm text-content-muted">
|
||||
{content.description}
|
||||
</p>
|
||||
<div className="mt-5 flex flex-wrap justify-center gap-2">
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-sm"
|
||||
className="inline-flex min-h-11 items-center justify-center border border-primary/50 bg-primary/10 px-4 text-sm font-bold text-base-content hover:bg-primary/15 focus-visible:ring-2 focus-visible:ring-primary disabled:cursor-wait disabled:opacity-70"
|
||||
disabled={isRetrying}
|
||||
onClick={onRetry}
|
||||
>
|
||||
{isRetrying ? "다시 불러오는 중..." : "다시 시도"}
|
||||
</button>
|
||||
<Link to={`/match/${matchId}`} className="btn btn-ghost btn-sm">
|
||||
<Link
|
||||
to={`/match/${matchId}`}
|
||||
className="inline-flex min-h-11 items-center justify-center border border-base-content/20 bg-base-100 px-4 text-sm font-bold text-base-content hover:bg-base-200 focus-visible:ring-2 focus-visible:ring-primary"
|
||||
>
|
||||
내전 상세로
|
||||
</Link>
|
||||
</div>
|
||||
@@ -417,7 +467,7 @@ function EmptyState({ message }: { message: string }) {
|
||||
return (
|
||||
<p
|
||||
role="status"
|
||||
className="border border-dashed border-base-content/10 px-4 py-8 text-center text-sm text-base-content/40"
|
||||
className="border border-dashed border-base-content/10 px-4 py-8 text-center text-sm text-content-muted"
|
||||
>
|
||||
{message}
|
||||
</p>
|
||||
|
||||
Reference in new issue
Block a user