218 lines
6.4 KiB
TypeScript
218 lines
6.4 KiB
TypeScript
import type {
|
|
BracketRoundView,
|
|
CompetitionDetailResponse,
|
|
CompetitionOutcome,
|
|
TeamId,
|
|
} from "@lolympus/contracts";
|
|
import { Link } from "react-router";
|
|
import { CompetitionSeriesHistory } from "./CompetitionSeriesHistory";
|
|
import { DoubleEliminationBracket } from "./DoubleEliminationBracket";
|
|
import { createCompetitionSeriesHistory } from "./competition-series-history";
|
|
import { createCompetitionBracketLayout } from "./competition-display-layout";
|
|
import { bracketRoundLabel } from "./double-elimination-bracket-layout";
|
|
import { RoundRobinTable } from "./RoundRobinTable";
|
|
import { SeriesScoreCard } from "./SeriesScoreCard";
|
|
|
|
export function CompetitionResults({
|
|
competition,
|
|
view = "all",
|
|
}: {
|
|
competition: CompetitionDetailResponse;
|
|
view?: "all" | "bracket" | "games";
|
|
}) {
|
|
const { projection } = competition;
|
|
const teamById = new Map(
|
|
competition.teams.map((team) => [team.teamId, team]),
|
|
);
|
|
|
|
if (view === "games") {
|
|
const hasSeriesHistory =
|
|
createCompetitionSeriesHistory(projection).length > 0;
|
|
return (
|
|
<div className="mb-6">
|
|
{hasSeriesHistory ? (
|
|
<CompetitionSeriesHistory
|
|
communityId={competition.communityId}
|
|
matchId={competition.matchId}
|
|
projection={projection}
|
|
teamById={teamById}
|
|
/>
|
|
) : (
|
|
<p
|
|
className="border border-dashed border-base-content/15 px-4 py-8 text-center text-sm text-base-content/45"
|
|
role="status"
|
|
>
|
|
기록된 공식 경기가 없습니다.
|
|
</p>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const seriesById = new Map(
|
|
projection.series.map((series) => [series.seriesId, series]),
|
|
);
|
|
const doubleEliminationLayout = createCompetitionBracketLayout(competition);
|
|
|
|
return (
|
|
<section className="mb-6 space-y-4" aria-labelledby="competition-heading">
|
|
<header className="flex flex-wrap items-end justify-between gap-3 border-b border-base-content/10 pb-3">
|
|
<div>
|
|
<p className="text-[11px] font-bold uppercase tracking-wider text-base-content/35">
|
|
Competition
|
|
</p>
|
|
<h2 id="competition-heading" className="mt-1 text-lg font-bold">
|
|
공식 경기 결과
|
|
</h2>
|
|
</div>
|
|
<div className="flex items-center gap-3">
|
|
<span className="text-xs text-base-content/40">
|
|
revision {competition.revision}
|
|
</span>
|
|
<Link
|
|
to={`/match/${competition.matchId}/team`}
|
|
className="border border-base-content/10 px-2.5 py-1.5 text-xs font-bold text-base-content/55 hover:border-primary/30 hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary"
|
|
>
|
|
팀 진행
|
|
</Link>
|
|
</div>
|
|
</header>
|
|
|
|
{projection.outcome && (
|
|
<OutcomeSummary outcome={projection.outcome} teamById={teamById} />
|
|
)}
|
|
|
|
{projection.formatType === "round-robin" && (
|
|
<RoundRobinTable standings={projection.standings} teamById={teamById} />
|
|
)}
|
|
|
|
{projection.rounds.length > 0 ? (
|
|
projection.formatType === "double-elimination" &&
|
|
doubleEliminationLayout ? (
|
|
<DoubleEliminationBracket
|
|
projection={projection}
|
|
layout={doubleEliminationLayout}
|
|
teamById={teamById}
|
|
/>
|
|
) : (
|
|
<GenericRoundGrid
|
|
rounds={projection.rounds}
|
|
seriesById={seriesById}
|
|
teamById={teamById}
|
|
/>
|
|
)
|
|
) : (
|
|
<p
|
|
className="border border-dashed border-base-content/15 px-4 py-5 text-sm text-base-content/45"
|
|
role="status"
|
|
>
|
|
편성된 공식 대진이 없습니다.
|
|
</p>
|
|
)}
|
|
|
|
{view === "all" && (
|
|
<CompetitionSeriesHistory
|
|
communityId={competition.communityId}
|
|
matchId={competition.matchId}
|
|
projection={projection}
|
|
teamById={teamById}
|
|
/>
|
|
)}
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function GenericRoundGrid({
|
|
rounds,
|
|
seriesById,
|
|
teamById,
|
|
}: {
|
|
rounds: BracketRoundView[];
|
|
seriesById: Map<
|
|
string,
|
|
CompetitionDetailResponse["projection"]["series"][number]
|
|
>;
|
|
teamById: Map<TeamId, CompetitionDetailResponse["teams"][number]>;
|
|
}) {
|
|
return (
|
|
<div className="overflow-x-auto pb-2">
|
|
<div className="grid min-w-max auto-cols-[17rem] grid-flow-col gap-4">
|
|
{rounds.map((round) => (
|
|
<RoundColumn
|
|
key={`${round.stage}:${round.roundNumber ?? 0}`}
|
|
round={round}
|
|
seriesById={seriesById}
|
|
teamById={teamById}
|
|
/>
|
|
))}
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function RoundColumn({
|
|
round,
|
|
seriesById,
|
|
teamById,
|
|
}: {
|
|
round: BracketRoundView;
|
|
seriesById: Map<
|
|
string,
|
|
CompetitionDetailResponse["projection"]["series"][number]
|
|
>;
|
|
teamById: Map<TeamId, CompetitionDetailResponse["teams"][number]>;
|
|
}) {
|
|
return (
|
|
<section aria-label={round.label} className="space-y-2">
|
|
<h3 className="px-1 text-xs font-bold text-base-content/45">
|
|
{bracketRoundLabel(round.stage, round.roundNumber)}
|
|
</h3>
|
|
<div className="space-y-3">
|
|
{round.seriesIds.map((seriesId) => {
|
|
const series = seriesById.get(seriesId);
|
|
return series ? (
|
|
<SeriesScoreCard
|
|
key={series.seriesId}
|
|
series={series}
|
|
teamById={teamById}
|
|
/>
|
|
) : null;
|
|
})}
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
function OutcomeSummary({
|
|
outcome,
|
|
teamById,
|
|
}: {
|
|
outcome: CompetitionOutcome;
|
|
teamById: Map<TeamId, CompetitionDetailResponse["teams"][number]>;
|
|
}) {
|
|
if (outcome.type === "paired-series") {
|
|
return (
|
|
<p className="border-l-2 border-success bg-success/5 px-3 py-2 text-sm text-base-content/65">
|
|
{outcome.completedSeriesIds.length + outcome.drawnSeriesIds.length}개
|
|
Series가 모두 종료되었습니다.
|
|
</p>
|
|
);
|
|
}
|
|
const leaders =
|
|
outcome.type === "round-robin"
|
|
? outcome.leaderTeamIds
|
|
: [outcome.championTeamId];
|
|
return (
|
|
<p className="border-l-2 border-success bg-success/5 px-3 py-2 text-sm">
|
|
<span className="mr-2 text-xs font-bold text-success">
|
|
{outcome.type === "round-robin" ? "1위" : "우승"}
|
|
</span>
|
|
<span className="font-bold">
|
|
{leaders
|
|
.map((teamId) => teamById.get(teamId)?.name ?? "알 수 없는 팀")
|
|
.join(", ")}
|
|
</span>
|
|
</p>
|
|
);
|
|
}
|