refactor: cut web results over to competition projections
This commit is contained in:
1 parent
7db97c540b
commit
6bddb666fc
13 files changed
+2153
-3885
No files matched your search
@@ -0,0 +1,185 @@
|
||||
import type {
|
||||
BracketRoundView,
|
||||
CompetitionDetailResponse,
|
||||
CompetitionOutcome,
|
||||
TeamId,
|
||||
} from "@lolympus/contracts";
|
||||
import { Link } from "react-router";
|
||||
import { RoundRobinTable } from "./RoundRobinTable";
|
||||
import { SeriesScoreCard } from "./SeriesScoreCard";
|
||||
|
||||
export function CompetitionResults({
|
||||
competition,
|
||||
}: {
|
||||
competition: CompetitionDetailResponse;
|
||||
}) {
|
||||
const { projection } = competition;
|
||||
const teamById = new Map(
|
||||
competition.teams.map((team) => [team.teamId, team]),
|
||||
);
|
||||
const seriesById = new Map(
|
||||
projection.series.map((series) => [series.seriesId, series]),
|
||||
);
|
||||
|
||||
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 ? (
|
||||
<div className="overflow-x-auto pb-2">
|
||||
<div className="grid min-w-max auto-cols-[17rem] grid-flow-col gap-4">
|
||||
{projection.rounds.map((round) => (
|
||||
<RoundColumn
|
||||
key={`${round.stage}:${round.roundNumber ?? 0}`}
|
||||
round={round}
|
||||
seriesById={seriesById}
|
||||
teamById={teamById}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<p
|
||||
className="border border-dashed border-base-content/15 px-4 py-5 text-sm text-base-content/45"
|
||||
role="status"
|
||||
>
|
||||
편성된 공식 대진이 없습니다.
|
||||
</p>
|
||||
)}
|
||||
|
||||
{projection.games.length > 0 && (
|
||||
<div className="border border-base-content/10 bg-base-content/[0.02] p-4">
|
||||
<h3 className="text-xs font-bold uppercase tracking-wider text-base-content/40">
|
||||
완료된 게임
|
||||
</h3>
|
||||
<ul className="mt-3 grid gap-2 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{projection.games.map((game) => (
|
||||
<li
|
||||
key={game.id}
|
||||
className="flex items-center justify-between gap-3 border border-base-content/8 bg-base-100 px-3 py-2 text-xs"
|
||||
>
|
||||
<span className="text-base-content/45">
|
||||
Game {game.displayNumber}
|
||||
</span>
|
||||
<span className="truncate font-semibold">
|
||||
{teamById.get(game.winnerTeamId)?.name ?? "알 수 없는 팀"} 승
|
||||
</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
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">
|
||||
{stageLabel(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>
|
||||
);
|
||||
}
|
||||
|
||||
function stageLabel(stage: BracketRoundView["stage"], round?: number) {
|
||||
switch (stage) {
|
||||
case "pair":
|
||||
return "대진";
|
||||
case "round-robin":
|
||||
return `${round ?? 1}라운드`;
|
||||
case "upper":
|
||||
return `승자조 ${round ?? 1}라운드`;
|
||||
case "lower":
|
||||
return `패자조 ${round ?? 1}라운드`;
|
||||
case "grand-final":
|
||||
return "그랜드 파이널";
|
||||
case "reset-final":
|
||||
return "리셋 파이널";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user