Files
lolympus-tournament-support/apps/web/src/pages/MatchTeamProgressPage.tsx
T
dahyeon 664af15255 feat: refresh the home page and separate match event types
Add an inhouse hero, Hall of Fame, rankings, and event-specific schedules. Carry the event type through the API and admin tools, and improve results and player history displays.
2026-11-10 22:13:55 +09:00

479 lines
16 KiB
TypeScript

import type {
CompetitionDetailResponse,
SeriesProjection,
} from "@lolympus/contracts";
import { ChevronDown, UsersRound } from "lucide-react";
import { useEffect, useRef } from "react";
import { Link, useParams, useSearchParams } from "react-router";
import { useCompetition, useTeamCompetition } from "../api/hooks";
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";
import { PageBody, PageHero, PlainPage } from "../ui";
export default function MatchTeamProgressPage() {
const { id } = useParams();
const [searchParams] = useSearchParams();
const selectedTeamId = searchParams.get("teamId") ?? undefined;
const isSelectingTeam = !selectedTeamId && searchParams.get("select") === "1";
const competitionQuery = useCompetition(id, DEFAULT_COMMUNITY_ID);
const teamQuery = useTeamCompetition(
id,
DEFAULT_COMMUNITY_ID,
selectedTeamId,
);
const refetchCompetition = competitionQuery.refetch;
const refetchTeam = teamQuery.refetch;
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,
);
const isRefetching = competitionQuery.isFetching || teamQuery.isFetching;
const revisionsMatch = isConsistentTeamProgressSnapshot(
competition,
teamView,
);
const revisionMismatchKey =
competition && teamView && !revisionsMatch
? `${competition.revision}:${teamView.revision}`
: null;
useEffect(() => {
if (!revisionMismatchKey) {
lastAutoRefetchedMismatchRef.current = null;
return;
}
if (
hasQueryError ||
isRefetching ||
lastAutoRefetchedMismatchRef.current === revisionMismatchKey
) {
return;
}
lastAutoRefetchedMismatchRef.current = revisionMismatchKey;
void Promise.all([refetchCompetition(), refetchTeam()]).catch(
() => undefined,
);
}, [
hasQueryError,
isRefetching,
refetchCompetition,
refetchTeam,
revisionMismatchKey,
]);
useEffect(() => {
if (isSelectingTeam || !teamViewId || !revisionsMatch) return;
contentHeadingRef.current?.focus({ preventScroll: true });
}, [isSelectingTeam, revisionsMatch, teamViewId]);
function retryBoth() {
void Promise.all([refetchCompetition(), refetchTeam()]).catch(
() => undefined,
);
}
if (isSelectingTeam && competition) {
return <TeamSelectionState competition={competition} matchId={id} />;
}
if (competitionQuery.isLoading || teamQuery.isLoading) {
return <TeamProgressLoadingState />;
}
if (hasQueryError) {
// The caller could not be resolved to a team from their identity — let them
// name the team instead, so the page stays usable without signing in.
if (
competition &&
!competitionQuery.error &&
shouldOfferTeamSelection([teamQuery.error], selectedTeamId)
) {
return <TeamSelectionState competition={competition} matchId={id} />;
}
return (
<TeamProgressProblemState
content={getTeamProgressErrorContent(
[competitionQuery.error, teamQuery.error].filter(Boolean),
)}
isRetrying={isRefetching}
matchId={id}
onRetry={retryBoth}
/>
);
}
if (!competition || !teamView) {
return (
<TeamProgressProblemState
content={getTeamProgressErrorContent([])}
isRetrying={isRefetching}
matchId={id}
onRetry={retryBoth}
/>
);
}
if (!revisionsMatch) {
return (
<TeamProgressProblemState
content={{
kind: "unknown",
title: isRefetching
? "최신 경기 정보를 맞추는 중입니다"
: "경기 정보의 revision이 일치하지 않습니다",
description: isRefetching
? "Competition과 팀 정보를 함께 다시 불러오고 있습니다."
: "일관된 경기 정보를 표시할 수 없어 두 응답을 다시 확인해야 합니다.",
}}
isRetrying={isRefetching}
matchId={id}
onRetry={retryBoth}
/>
);
}
const teamById = new Map(
competition.teams.map((team) => [team.teamId, team]),
);
const team = teamById.get(teamView.teamId);
const activeSeriesGroups = createTeamSeriesGroups(
teamView.activeSeries,
teamView.tournamentCodes,
);
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 (
<>
<PageHero
crumbs={[
{ label: "내전", to: "/" },
{ label: "내전 상세", to: `/match/${id}` },
{ label: "팀 경기 현황" },
]}
eyebrow="팀 경기 현황"
title={
<span ref={contentHeadingRef} tabIndex={-1} className="outline-none">
{team?.name ?? (selectedTeamId ? "팀" : "내 팀")}
</span>
}
meta="다음 상대와 세트별 토너먼트 코드를 한곳에서 확인할 수 있습니다."
flush
actions={
<Link
to={`/match/${id}/team?select=1`}
className="inline-flex h-10 shrink-0 items-center justify-center gap-2 rounded-field bg-on-ink/10 px-4 text-sm font-bold text-on-ink transition-colors hover:bg-on-ink/20"
>
<UsersRound className="h-4 w-4" aria-hidden="true" />
팀 변경
</Link>
}
/>
<PlainPage>
<div className={team ? "mb-8 grid items-start gap-6 lg:grid-cols-[minmax(0,1.6fr)_minmax(0,1fr)]" : "mb-8"}>
<section aria-labelledby="active-series-heading">
<SectionHeading
id="active-series-heading"
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="현재 준비하거나 진행할 대진이 없습니다." />
)}
<Link
to={`/match/${id}?tab=bracket`}
className="mt-3 inline-flex min-h-10 items-center text-sm font-semibold text-primary hover:underline"
>
전체 대진표 보기
</Link>
</section>
{team && (
<section aria-labelledby="roster-heading">
<SectionHeading
id="roster-heading"
title="팀 구성"
description={`${team.members.length}명의 라인업을 포지션 순서로 보여줍니다.`}
/>
<ul className="lts-panel divide-y divide-line">
{sortTeamMembersForRoster(team.members).map((member) => (
<li
key={member.userId}
className="grid min-h-12 grid-cols-[4.5rem_minmax(0,1fr)] items-center gap-3 px-4 py-2 sm:px-5"
>
<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}
</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>
</li>
))}
</ul>
</section>
)}
</div>
<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>
</PlainPage>
</>
);
}
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">
{title}
</h2>
<p className="mt-0.5 text-xs text-content-muted">{description}</p>
</div>
);
}
function TeamSelectionState({
competition,
matchId,
}: {
competition: CompetitionDetailResponse;
matchId: string | undefined;
}) {
const headingRef = useRef<HTMLHeadingElement>(null);
useEffect(() => {
headingRef.current?.focus({ preventScroll: true });
}, []);
return (
<>
<PageHero
crumbs={[
{ label: "내전", to: "/" },
{ label: "내전 상세", to: `/match/${matchId}` },
{ label: "팀 선택" },
]}
eyebrow="팀 경기 현황"
title={
<span ref={headingRef} tabIndex={-1} className="outline-none">
팀 선택
</span>
}
meta="진행 상황과 토너먼트 코드를 확인할 팀을 선택해 주세요."
/>
<PageBody>
{competition.teams.length > 0 ? (
<ul className="grid gap-3 sm:grid-cols-2">
{competition.teams.map((team) => (
<li key={team.teamId}>
<Link
to={`/match/${matchId}/team?teamId=${team.teamId}`}
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 break-words text-sm font-bold">
{team.name}
</span>
<span className="shrink-0 text-xs text-content-muted">
{team.members.length}명
</span>
</Link>
</li>
))}
</ul>
) : (
<EmptyState message="구성된 팀이 없습니다." />
)}
</PageBody>
</>
);
}
function TeamProgressLoadingState() {
return (
<main
className="mx-auto max-w-5xl space-y-3 px-4 py-12 sm:px-6"
aria-busy="true"
aria-label="팀 진행 정보를 불러오는 중"
role="status"
>
<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>
);
}
function TeamProgressProblemState({
content,
isRetrying,
matchId,
onRetry,
}: {
content: TeamProgressErrorContent;
isRetrying: boolean;
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
role="alert"
aria-busy={isRetrying}
className="border border-base-content/10 bg-base-100 px-5 py-8 text-center"
>
<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="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="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>
</section>
</main>
);
}
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-content-muted"
>
{message}
</p>
);
}