1846 lines
61 KiB
TypeScript
1846 lines
61 KiB
TypeScript
import { useEffect, useRef, useState } from "react";
|
||
import { ChevronLeft, ChevronRight } from "lucide-react";
|
||
import { Link, useLocation, useNavigate, useParams } from "react-router";
|
||
import {
|
||
Area,
|
||
AreaChart,
|
||
CartesianGrid,
|
||
Line,
|
||
ReferenceDot,
|
||
ReferenceLine,
|
||
ResponsiveContainer,
|
||
Tooltip,
|
||
XAxis,
|
||
YAxis,
|
||
} from "recharts";
|
||
import { useCompetition, useDdragonManifest, useInternalMatchDetail } from "../api/hooks";
|
||
import type { ApiInternalMatchDetailResponse, TeamSide } from "../api/types";
|
||
import { DEFAULT_COMMUNITY_ID } from "../config";
|
||
import {
|
||
championDisplayName,
|
||
championIconUrl,
|
||
} from "../lib/ddragon";
|
||
import {
|
||
sideShortLabel,
|
||
teamIndexColorClasses,
|
||
teamIndexLabel,
|
||
} from "../lib/league";
|
||
import {
|
||
internalMatchDetailPath,
|
||
internalMatchGamePath,
|
||
} from "../lib/internal-match-routes";
|
||
import { selectInternalMatchGame } from "../lib/internal-match-game-selection";
|
||
import { groupRecordedSets, type RecordedSeries } from "../lib/internal-match-series";
|
||
import { getSeriesHistoryResultLabel, shouldDisplaySeriesHistoryScore } from "../components/competition/competition-series-history";
|
||
import { LANE_LABELS } from "../lib/riot-history";
|
||
import {
|
||
filterTimelineEvents,
|
||
normalizeObjectiveEvents,
|
||
normalizeTimelineEvents,
|
||
projectTimelineEventMarkers,
|
||
selectTimelineEventSource,
|
||
summarizeDragonTypes,
|
||
type NormalizedTimelineEvent,
|
||
type TimelineEventFilter,
|
||
} from "../lib/internal-match-timeline";
|
||
import {
|
||
InternalGameAnalysisPanel,
|
||
InternalGameDetailTabBar,
|
||
type InternalGameDetailTab,
|
||
} from "../components/InternalGameAnalysisTabs";
|
||
import {
|
||
ItemIcon,
|
||
RuneIcon,
|
||
RuneStyleIcon,
|
||
SummonerSpellIcon,
|
||
} from "../components/ItemTooltip";
|
||
|
||
import {
|
||
Btn,
|
||
EmptyNote,
|
||
LoadingNote,
|
||
MetaDot,
|
||
PageBody,
|
||
PageHero,
|
||
PlainPage,
|
||
} from "../ui";
|
||
type MatchGameDetail = ApiInternalMatchDetailResponse["games"][number];
|
||
type MatchGameTeam = MatchGameDetail["teams"][number];
|
||
type MatchGameParticipant = MatchGameTeam["participants"][number];
|
||
type TimelineMetric = "gold" | "xp";
|
||
type MatchGameBackTarget = {
|
||
to: string;
|
||
label: string;
|
||
};
|
||
type MatchGameNavigationState = {
|
||
backTo: string;
|
||
backLabel: string;
|
||
};
|
||
|
||
const TIMELINE_METRICS: Array<{ id: TimelineMetric; label: string }> = [
|
||
{ id: "gold", label: "골드" },
|
||
{ id: "xp", label: "경험치" },
|
||
];
|
||
|
||
const TIMELINE_EVENT_FILTERS: Array<{
|
||
id: TimelineEventFilter;
|
||
label: string;
|
||
}> = [
|
||
{ id: "all", label: "전체" },
|
||
{ id: "objective", label: "오브젝트" },
|
||
{ id: "kill", label: "킬" },
|
||
{ id: "structure", label: "구조물" },
|
||
];
|
||
|
||
function isRecord(value: unknown): value is Record<string, unknown> {
|
||
return typeof value === "object" && value !== null;
|
||
}
|
||
|
||
function resolveBackTarget(
|
||
state: unknown,
|
||
fallbackTo: string,
|
||
): MatchGameBackTarget {
|
||
if (
|
||
isRecord(state) &&
|
||
typeof state.backTo === "string" &&
|
||
state.backTo.startsWith("/") &&
|
||
!state.backTo.startsWith("//")
|
||
) {
|
||
return {
|
||
to: state.backTo,
|
||
label:
|
||
typeof state.backLabel === "string" && state.backLabel.trim().length > 0
|
||
? state.backLabel.trim()
|
||
: "돌아가기",
|
||
};
|
||
}
|
||
|
||
return {
|
||
to: fallbackTo,
|
||
label: "경기 기록으로 돌아가기",
|
||
};
|
||
}
|
||
|
||
function createNavigationState(
|
||
backTarget: MatchGameBackTarget,
|
||
fallbackTo: string,
|
||
): MatchGameNavigationState | undefined {
|
||
if (backTarget.to === fallbackTo) return undefined;
|
||
return {
|
||
backTo: backTarget.to,
|
||
backLabel: backTarget.label,
|
||
};
|
||
}
|
||
|
||
function formatDateTime(value: string | number) {
|
||
return new Intl.DateTimeFormat("ko-KR", {
|
||
month: "long",
|
||
day: "numeric",
|
||
hour: "2-digit",
|
||
minute: "2-digit",
|
||
}).format(new Date(value));
|
||
}
|
||
|
||
function formatDuration(seconds: number) {
|
||
const minutes = Math.floor(seconds / 60);
|
||
const rest = seconds % 60;
|
||
return `${minutes}:${String(rest).padStart(2, "0")}`;
|
||
}
|
||
|
||
function formatNumber(value: number) {
|
||
return new Intl.NumberFormat("ko-KR").format(value);
|
||
}
|
||
|
||
function formatCompactNumber(value: number) {
|
||
if (value >= 1000) return `${(value / 1000).toFixed(1)}K`;
|
||
return String(value);
|
||
}
|
||
|
||
function formatSignedCompactNumber(value: number) {
|
||
if (value === 0) return "0";
|
||
return `${value > 0 ? "+" : "-"}${formatCompactNumber(Math.abs(value))}`;
|
||
}
|
||
|
||
function formatGameVersion(value: string | undefined) {
|
||
if (!value) return null;
|
||
const [major, minor] = value.split(".");
|
||
return major && minor ? `${major}.${minor}` : value;
|
||
}
|
||
|
||
function formatKda(kills: number, deaths: number, assists: number) {
|
||
if (deaths === 0) return kills + assists > 0 ? "Perfect" : "-";
|
||
return ((kills + assists) / deaths).toFixed(2);
|
||
}
|
||
|
||
function formatPercent(value: number) {
|
||
return `${value}%`;
|
||
}
|
||
|
||
function formatDragonTypeSummary(
|
||
values: Array<{ label: string; count: number }>,
|
||
total: number,
|
||
) {
|
||
if (values.length === 0) return total > 0 ? "유형 정보 없음" : "-";
|
||
return values
|
||
.map(({ label, count }) => (count > 1 ? `${label}×${count}` : label))
|
||
.join(" · ");
|
||
}
|
||
|
||
function barWidth(value: number, max: number) {
|
||
return `${Math.max(0, Math.min(100, max > 0 ? (value / max) * 100 : 0))}%`;
|
||
}
|
||
|
||
function sideLabel(side: TeamSide) {
|
||
return sideShortLabel(side);
|
||
}
|
||
|
||
function sideTone(side: TeamSide) {
|
||
return side === "blue"
|
||
? {
|
||
border: "border-win-line",
|
||
bg: "bg-win-tint",
|
||
text: "text-win",
|
||
bar: "bg-win",
|
||
}
|
||
: {
|
||
border: "border-loss-line",
|
||
bg: "bg-loss-tint",
|
||
text: "text-loss",
|
||
bar: "bg-loss",
|
||
};
|
||
}
|
||
|
||
function teamTotals(team: MatchGameTeam) {
|
||
return team.participants.reduce(
|
||
(totals, participant) => ({
|
||
kills: totals.kills + participant.kills,
|
||
deaths: totals.deaths + participant.deaths,
|
||
assists: totals.assists + participant.assists,
|
||
gold: totals.gold + participant.gold,
|
||
damage: totals.damage + participant.damageDealtToChampions,
|
||
damageTaken: totals.damageTaken + (participant.damageTaken ?? 0),
|
||
vision: totals.vision + participant.visionScore,
|
||
}),
|
||
{
|
||
kills: 0,
|
||
deaths: 0,
|
||
assists: 0,
|
||
gold: 0,
|
||
damage: 0,
|
||
damageTaken: 0,
|
||
vision: 0,
|
||
},
|
||
);
|
||
}
|
||
|
||
function getTeamName(
|
||
detail: ApiInternalMatchDetailResponse,
|
||
teamIndex: number,
|
||
) {
|
||
return teamIndexLabel(
|
||
teamIndex,
|
||
detail.match.teams.find((team) => team.teamIndex === teamIndex)?.name,
|
||
);
|
||
}
|
||
|
||
function WinBadge({ win }: { win: boolean }) {
|
||
return win ? (
|
||
<span className="inline-flex items-center border border-accent/60 bg-accent px-2 py-0.5 text-xs font-black text-accent-content">
|
||
승리
|
||
</span>
|
||
) : (
|
||
<span className="inline-flex items-center border border-base-content/15 px-2 py-0.5 text-xs font-bold text-base-content/40">
|
||
패배
|
||
</span>
|
||
);
|
||
}
|
||
|
||
function ChampionAvatar({
|
||
participant,
|
||
manifest,
|
||
size = "h-9 w-9",
|
||
}: {
|
||
participant: MatchGameParticipant;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
size?: string;
|
||
}) {
|
||
const icon = championIconUrl(manifest, participant.championId);
|
||
const name =
|
||
championDisplayName(manifest, participant.championId) ??
|
||
String(participant.championId);
|
||
return (
|
||
<span
|
||
className={`relative ${size} shrink-0 overflow-hidden bg-base-content/10`}
|
||
title={name}
|
||
>
|
||
{icon ? (
|
||
<img src={icon} alt={name} className="h-full w-full object-cover" />
|
||
) : null}
|
||
{participant.championLevel > 0 ? (
|
||
<span className="absolute bottom-0 right-0 min-w-4 bg-base-300 px-1 text-center text-[10px] font-black leading-4 text-base-content">
|
||
{participant.championLevel}
|
||
</span>
|
||
) : null}
|
||
</span>
|
||
);
|
||
}
|
||
|
||
function SpellRuneStrip({
|
||
participant,
|
||
manifest,
|
||
}: {
|
||
participant: MatchGameParticipant;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
}) {
|
||
return (
|
||
<div className="flex items-center gap-1.5">
|
||
<div className="grid grid-cols-1 gap-0.5">
|
||
{[0, 1].map((index) => (
|
||
<SummonerSpellIcon
|
||
key={`spell-${index}`}
|
||
spellId={participant.summonerSpells[index] ?? 0}
|
||
manifest={manifest}
|
||
/>
|
||
))}
|
||
</div>
|
||
<div className="grid grid-cols-1 gap-0.5">
|
||
<RuneIcon runeId={participant.perks.keystone} manifest={manifest} />
|
||
<RuneStyleIcon
|
||
styleId={participant.perks.subStyle ?? participant.perks.primaryStyle}
|
||
manifest={manifest}
|
||
/>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function ItemStrip({
|
||
participant,
|
||
manifest,
|
||
}: {
|
||
participant: MatchGameParticipant;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
}) {
|
||
const itemIds = [
|
||
...Array.from({ length: 6 }, (_, index) => participant.items[index] ?? 0),
|
||
participant.trinket,
|
||
];
|
||
|
||
return (
|
||
<div className="grid grid-cols-7 gap-0.5">
|
||
{itemIds.map((itemId, index) => (
|
||
<ItemIcon
|
||
key={`${itemId}-${index}`}
|
||
itemId={itemId}
|
||
manifest={manifest}
|
||
trinket={index === 6}
|
||
className="h-8 w-8"
|
||
imageClassName=""
|
||
/>
|
||
))}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function PercentBar({ value, side }: { value: number; side: TeamSide }) {
|
||
const width = `${Math.max(0, Math.min(100, value))}%`;
|
||
return (
|
||
<div className="mt-1 h-1.5 bg-base-content/8">
|
||
<div className={`h-full ${sideTone(side).bar}`} style={{ width }} />
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function PlayerIdentityCell({
|
||
participant,
|
||
manifest,
|
||
avatarSize = "h-12 w-12",
|
||
nameMaxWidth = "max-w-[150px]",
|
||
}: {
|
||
participant: MatchGameParticipant;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
avatarSize?: string;
|
||
nameMaxWidth?: string;
|
||
}) {
|
||
const location = useLocation();
|
||
const historyBackTo = `${location.pathname}${location.search}${location.hash}`;
|
||
const lane =
|
||
LANE_LABELS[participant.teamPosition] ?? participant.teamPosition ?? "-";
|
||
const nameNode = (
|
||
<>
|
||
{participant.summonerName}
|
||
{participant.tagLine ? (
|
||
<span className="font-normal text-base-content/30">
|
||
{" "}
|
||
#{participant.tagLine}
|
||
</span>
|
||
) : null}
|
||
</>
|
||
);
|
||
|
||
return (
|
||
<div className="flex min-w-0 items-center gap-2">
|
||
<ChampionAvatar
|
||
participant={participant}
|
||
manifest={manifest}
|
||
size={avatarSize}
|
||
/>
|
||
<SpellRuneStrip participant={participant} manifest={manifest} />
|
||
<div className="min-w-0">
|
||
{participant.userId ? (
|
||
<Link
|
||
to={`/users/${participant.userId}/history?queueGroup=internal`}
|
||
state={{ backTo: historyBackTo }}
|
||
className={`block ${nameMaxWidth} truncate text-sm font-bold text-base-content hover:text-primary`}
|
||
>
|
||
{nameNode}
|
||
</Link>
|
||
) : (
|
||
<span
|
||
className={`block ${nameMaxWidth} truncate text-sm font-bold text-base-content`}
|
||
>
|
||
{nameNode}
|
||
</span>
|
||
)}
|
||
<div className="mt-0.5 flex items-center gap-1.5">
|
||
<span className="text-xs text-base-content/35">{lane}</span>
|
||
{(participant.firstBloodKill || participant.firstBloodAssist) && (
|
||
<span className="inline-flex border border-amber-400/30 bg-amber-400/10 px-1 text-[10px] font-black text-gold">
|
||
{participant.firstBloodKill ? "FB" : "FBA"}
|
||
</span>
|
||
)}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function PlayerRow({
|
||
participant,
|
||
manifest,
|
||
teamDamageTaken,
|
||
}: {
|
||
participant: MatchGameParticipant;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
teamDamageTaken: number;
|
||
}) {
|
||
const takenShare =
|
||
teamDamageTaken > 0
|
||
? ((participant.damageTaken ?? 0) / teamDamageTaken) * 100
|
||
: 0;
|
||
|
||
return (
|
||
<tr className="border-t border-base-content/5 hover:bg-base-content/[0.02]">
|
||
<td className="px-3 py-2.5">
|
||
<PlayerIdentityCell participant={participant} manifest={manifest} />
|
||
</td>
|
||
<td className="px-3 py-2.5 text-center">
|
||
<div className="text-sm font-black tabular-nums text-base-content">
|
||
{participant.kills}
|
||
<span className="text-base-content/25"> / </span>
|
||
<span className="text-loss">{participant.deaths}</span>
|
||
<span className="text-base-content/25"> / </span>
|
||
{participant.assists}
|
||
</div>
|
||
<div className="text-xs font-bold tabular-nums text-base-content/40">
|
||
KDA {formatKda(
|
||
participant.kills,
|
||
participant.deaths,
|
||
participant.assists,
|
||
)}
|
||
<span className="ml-1 text-base-content/35">
|
||
· KP {participant.killParticipation}%
|
||
</span>
|
||
</div>
|
||
</td>
|
||
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
|
||
{formatNumber(participant.damageDealtToChampions)}
|
||
<div className="mx-auto w-16">
|
||
<PercentBar value={participant.damageShare} side={participant.side} />
|
||
</div>
|
||
<span className="text-base-content/35">
|
||
{formatPercent(participant.damageShare)}
|
||
</span>
|
||
</td>
|
||
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
|
||
{formatNumber(participant.damageTaken ?? 0)}
|
||
<div className="mx-auto w-16">
|
||
<PercentBar value={takenShare} side={participant.side} />
|
||
</div>
|
||
<span className="text-base-content/35">{Math.round(takenShare)}%</span>
|
||
</td>
|
||
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
|
||
{participant.visionScore}
|
||
<span className="block text-base-content/35">
|
||
와드 {participant.wardsPlaced ?? 0}/{participant.wardsKilled ?? 0}
|
||
</span>
|
||
<span className="block text-base-content/30">
|
||
제어 {participant.controlWardsBought ?? 0}
|
||
</span>
|
||
</td>
|
||
<td className="px-3 py-2.5 text-center text-xs tabular-nums text-base-content/60">
|
||
{participant.cs}
|
||
<span className="block text-base-content/35">
|
||
{participant.csPerMin}/m
|
||
</span>
|
||
<span className="mt-1 block font-bold text-base-content/55">
|
||
{formatCompactNumber(participant.gold)}
|
||
<span className="ml-1 font-normal text-base-content/30">
|
||
{formatNumber(participant.gpm)} GPM
|
||
</span>
|
||
</span>
|
||
</td>
|
||
<td className="px-3 py-2.5">
|
||
<ItemStrip participant={participant} manifest={manifest} />
|
||
</td>
|
||
</tr>
|
||
);
|
||
}
|
||
|
||
function PlayerCard({
|
||
participant,
|
||
manifest,
|
||
teamDamageTaken,
|
||
}: {
|
||
participant: MatchGameParticipant;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
teamDamageTaken: number;
|
||
}) {
|
||
const takenShare =
|
||
teamDamageTaken > 0
|
||
? ((participant.damageTaken ?? 0) / teamDamageTaken) * 100
|
||
: 0;
|
||
|
||
return (
|
||
<div className="p-3">
|
||
<div className="flex items-start justify-between gap-2">
|
||
<PlayerIdentityCell participant={participant} manifest={manifest} />
|
||
<div className="shrink-0 text-right">
|
||
<div className="text-sm font-black tabular-nums text-base-content">
|
||
{participant.kills}
|
||
<span className="text-base-content/25"> / </span>
|
||
<span className="text-loss">{participant.deaths}</span>
|
||
<span className="text-base-content/25"> / </span>
|
||
{participant.assists}
|
||
</div>
|
||
<div className="text-[11px] font-bold tabular-nums text-base-content/40">
|
||
KDA {formatKda(
|
||
participant.kills,
|
||
participant.deaths,
|
||
participant.assists,
|
||
)}
|
||
<span className="ml-1 text-base-content/35">
|
||
· KP {participant.killParticipation}%
|
||
</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div className="mt-2">
|
||
<ItemStrip participant={participant} manifest={manifest} />
|
||
</div>
|
||
<div className="mt-2 grid grid-cols-2 gap-2 text-[11px] tabular-nums sm:grid-cols-4">
|
||
<div className="border border-base-content/8 px-2 py-1.5">
|
||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||
가한 피해량
|
||
</div>
|
||
<div className="mt-0.5 font-black text-base-content/70">
|
||
{formatNumber(participant.damageDealtToChampions)}
|
||
<span className="ml-1 font-bold text-base-content/35">
|
||
{formatPercent(participant.damageShare)}
|
||
</span>
|
||
</div>
|
||
<PercentBar value={participant.damageShare} side={participant.side} />
|
||
</div>
|
||
<div className="border border-base-content/8 px-2 py-1.5">
|
||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||
받은 피해량
|
||
</div>
|
||
<div className="mt-0.5 font-black text-base-content/70">
|
||
{formatNumber(participant.damageTaken ?? 0)}
|
||
<span className="ml-1 font-bold text-base-content/35">
|
||
{Math.round(takenShare)}%
|
||
</span>
|
||
</div>
|
||
<PercentBar value={takenShare} side={participant.side} />
|
||
</div>
|
||
<div className="border border-base-content/8 px-2 py-1.5">
|
||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||
CS · 경제
|
||
</div>
|
||
<div className="mt-0.5 font-black text-base-content/70">
|
||
{participant.cs}
|
||
<span className="ml-1 font-bold text-base-content/35">
|
||
{participant.csPerMin}/m
|
||
</span>
|
||
<span className="mt-1 block text-base-content/60">
|
||
{formatCompactNumber(participant.gold)}
|
||
<span className="ml-1 font-bold text-base-content/35">
|
||
{formatNumber(participant.gpm)} GPM
|
||
</span>
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div className="border border-base-content/8 px-2 py-1.5">
|
||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||
시야
|
||
</div>
|
||
<div className="mt-0.5 font-black text-base-content/70">
|
||
{participant.visionScore}
|
||
<span className="ml-1 font-bold text-base-content/35">
|
||
{participant.wardsPlaced ?? 0}/{participant.wardsKilled ?? 0}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function TeamScoreHeader({
|
||
team,
|
||
detail,
|
||
}: {
|
||
team: MatchGameTeam;
|
||
detail: ApiInternalMatchDetailResponse;
|
||
}) {
|
||
const tone = sideTone(team.side);
|
||
const teamTone = teamIndexColorClasses(team.teamIndex);
|
||
const totals = teamTotals(team);
|
||
|
||
return (
|
||
<div
|
||
className={`border-b border-base-content/8 px-4 py-3 ${tone.bg} ${tone.border}`}
|
||
>
|
||
<div className="flex flex-col gap-3 lg:flex-row lg:items-center lg:justify-between">
|
||
<div className="flex min-w-0 items-center gap-3">
|
||
<span
|
||
className={`h-8 w-1 shrink-0 ${teamTone.bar}`}
|
||
aria-hidden="true"
|
||
/>
|
||
<div className="min-w-0">
|
||
<div className="flex flex-wrap items-center gap-2">
|
||
<h2 className={`text-sm font-black ${teamTone.text}`}>
|
||
{getTeamName(detail, team.teamIndex)}
|
||
</h2>
|
||
<span
|
||
className={`border px-2 py-0.5 text-xs font-black ${tone.text} ${tone.border}`}
|
||
>
|
||
{sideLabel(team.side)}
|
||
</span>
|
||
<WinBadge win={team.win} />
|
||
</div>
|
||
<div className="mt-1 text-xs text-base-content/45">
|
||
타워 {team.objectives.tower} · 드래곤 {team.objectives.dragon} ·
|
||
억제기 {team.objectives.inhibitor} · 바론 {team.objectives.baron}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div className="flex shrink-0 items-center gap-4 text-sm font-black tabular-nums">
|
||
<div className="flex items-baseline gap-1.5">
|
||
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||
KDA
|
||
</span>
|
||
<span className="text-base-content">
|
||
{totals.kills} / {totals.deaths} / {totals.assists}
|
||
</span>
|
||
</div>
|
||
<div className="flex items-baseline gap-1.5">
|
||
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/35">
|
||
Gold
|
||
</span>
|
||
<span className="text-base-content">
|
||
{formatCompactNumber(totals.gold)}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function BanStrip({
|
||
bans,
|
||
manifest,
|
||
}: {
|
||
bans: MatchGameTeam["bans"] | undefined;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
}) {
|
||
const sortedBans = [...(bans ?? [])].sort(
|
||
(left, right) => left.pickTurn - right.pickTurn,
|
||
);
|
||
return (
|
||
<div className="flex flex-wrap items-center justify-start gap-1.5 sm:justify-end">
|
||
{sortedBans.length > 0 ? (
|
||
sortedBans.map((ban) => {
|
||
const icon = championIconUrl(manifest, ban.championId);
|
||
const name =
|
||
championDisplayName(manifest, ban.championId) ??
|
||
String(ban.championId);
|
||
return (
|
||
<span
|
||
key={`${ban.championId}-${ban.pickTurn}`}
|
||
className="h-8 w-8 overflow-hidden border border-base-content/5 bg-base-content/10 opacity-80"
|
||
title={name}
|
||
>
|
||
{icon ? (
|
||
<img
|
||
src={icon}
|
||
alt={name}
|
||
className="h-full w-full object-cover"
|
||
/>
|
||
) : null}
|
||
</span>
|
||
);
|
||
})
|
||
) : (
|
||
<span className="text-xs font-bold text-base-content/30">밴 없음</span>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function PostgameBreakdown({
|
||
selectedGame,
|
||
detail,
|
||
manifest,
|
||
}: {
|
||
selectedGame: MatchGameDetail;
|
||
detail: ApiInternalMatchDetailResponse;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
}) {
|
||
const orderedTeams = [...selectedGame.teams].sort((left, right) =>
|
||
left.side === right.side ? 0 : left.side === "blue" ? -1 : 1,
|
||
);
|
||
const version = formatGameVersion(selectedGame.gameVersion);
|
||
|
||
return (
|
||
<section className="mt-5 overflow-hidden border border-base-content/10 bg-base-100">
|
||
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-base-content/8 px-4 py-3">
|
||
<h2 className="text-sm font-black text-base-content">경기 요약</h2>
|
||
<div className="flex flex-wrap items-center gap-2 text-xs font-bold text-base-content/35">
|
||
{version ? <span>Ver. {version}</span> : null}
|
||
<span>{formatDuration(selectedGame.gameDuration)}</span>
|
||
<span className="font-mono">{selectedGame.riotMatchId}</span>
|
||
</div>
|
||
</div>
|
||
<div className="grid gap-0 sm:grid-cols-2">
|
||
{orderedTeams.map((team) => {
|
||
const tone = sideTone(team.side);
|
||
const teamTone = teamIndexColorClasses(team.teamIndex);
|
||
return (
|
||
<div
|
||
key={`${team.side}-bans`}
|
||
className={`flex flex-wrap items-center justify-between gap-2 border-b border-base-content/8 px-4 py-2.5 last:border-b-0 sm:border-b-0 sm:border-r sm:last:border-r-0 ${tone.bg}`}
|
||
>
|
||
<div className="flex items-center gap-2">
|
||
<span className={`text-xs font-black ${teamTone.text}`}>
|
||
{getTeamName(detail, team.teamIndex)}
|
||
</span>
|
||
<span className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||
밴
|
||
</span>
|
||
</div>
|
||
<BanStrip bans={team.bans} manifest={manifest} />
|
||
</div>
|
||
);
|
||
})}
|
||
</div>
|
||
<ObjectiveComparisonStrip selectedGame={selectedGame} />
|
||
<GoldComparisonStrip selectedGame={selectedGame} detail={detail} />
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function ObjectiveComparisonStrip({
|
||
selectedGame,
|
||
}: {
|
||
selectedGame: MatchGameDetail;
|
||
}) {
|
||
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
|
||
const redTeam = selectedGame.teams.find((team) => team.side === "red");
|
||
if (!blueTeam || !redTeam) return null;
|
||
|
||
const events = normalizeObjectiveEvents(selectedGame.objectiveEvents ?? []);
|
||
const blueDragonTypes = formatDragonTypeSummary(
|
||
summarizeDragonTypes(events, "blue"),
|
||
blueTeam.objectives.dragon,
|
||
);
|
||
const redDragonTypes = formatDragonTypeSummary(
|
||
summarizeDragonTypes(events, "red"),
|
||
redTeam.objectives.dragon,
|
||
);
|
||
const objectives = [
|
||
{
|
||
key: "tower",
|
||
label: "포탑",
|
||
blue: blueTeam.objectives.tower,
|
||
red: redTeam.objectives.tower,
|
||
},
|
||
{
|
||
key: "dragon",
|
||
label: "드래곤",
|
||
blue: blueTeam.objectives.dragon,
|
||
red: redTeam.objectives.dragon,
|
||
blueDetail: blueDragonTypes,
|
||
redDetail: redDragonTypes,
|
||
},
|
||
{
|
||
key: "inhibitor",
|
||
label: "억제기",
|
||
blue: blueTeam.objectives.inhibitor,
|
||
red: redTeam.objectives.inhibitor,
|
||
},
|
||
{
|
||
key: "baron",
|
||
label: "바론",
|
||
blue: blueTeam.objectives.baron,
|
||
red: redTeam.objectives.baron,
|
||
},
|
||
{
|
||
key: "riftHerald",
|
||
label: "전령",
|
||
blue: blueTeam.objectives.riftHerald,
|
||
red: redTeam.objectives.riftHerald,
|
||
},
|
||
{
|
||
key: "voidGrub",
|
||
label: "공허 유충",
|
||
blue: blueTeam.objectives.voidGrub,
|
||
red: redTeam.objectives.voidGrub,
|
||
},
|
||
{
|
||
key: "elderDragon",
|
||
label: "장로",
|
||
blue: blueTeam.objectives.elderDragon,
|
||
red: redTeam.objectives.elderDragon,
|
||
},
|
||
];
|
||
|
||
return (
|
||
<div className="border-t border-base-content/8 bg-base-content/[0.01]">
|
||
<h3 className="sr-only">오브젝트 비교</h3>
|
||
<div className="grid grid-cols-2 sm:grid-cols-4 lg:grid-cols-7">
|
||
{objectives.map((objective) => (
|
||
<div
|
||
key={objective.key}
|
||
className="border-b border-r border-base-content/8 px-3 py-2.5 last:border-r-0 lg:border-b-0"
|
||
aria-label={`${objective.label}: 블루 ${objective.blue}, 레드 ${objective.red}`}
|
||
>
|
||
<div className="grid grid-cols-[1fr_auto_1fr] items-center gap-2 text-xs tabular-nums">
|
||
<span
|
||
className={`text-right font-black ${
|
||
objective.blue > objective.red
|
||
? "text-win"
|
||
: "text-base-content/50"
|
||
}`}
|
||
>
|
||
{objective.blue}
|
||
</span>
|
||
<span className="text-[10px] font-bold text-base-content/35">
|
||
{objective.label}
|
||
</span>
|
||
<span
|
||
className={`font-black ${
|
||
objective.red > objective.blue
|
||
? "text-loss"
|
||
: "text-base-content/50"
|
||
}`}
|
||
>
|
||
{objective.red}
|
||
</span>
|
||
</div>
|
||
{objective.key === "dragon" ? (
|
||
<div className="mt-1 grid grid-cols-2 gap-2 text-[9px] font-bold leading-tight">
|
||
<span className="text-right text-win">
|
||
{objective.blueDetail}
|
||
</span>
|
||
<span className="text-loss">{objective.redDetail}</span>
|
||
</div>
|
||
) : null}
|
||
</div>
|
||
))}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function GoldComparisonStrip({
|
||
selectedGame,
|
||
detail,
|
||
}: {
|
||
selectedGame: MatchGameDetail;
|
||
detail: ApiInternalMatchDetailResponse;
|
||
}) {
|
||
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
|
||
const redTeam = selectedGame.teams.find((team) => team.side === "red");
|
||
if (!blueTeam || !redTeam) return null;
|
||
|
||
const blueTotals = teamTotals(blueTeam);
|
||
const redTotals = teamTotals(redTeam);
|
||
const goldDiff = blueTotals.gold - redTotals.gold;
|
||
const maxGold = Math.max(1, blueTotals.gold, redTotals.gold);
|
||
const leaderSide =
|
||
goldDiff > 0 ? "blue" : goldDiff < 0 ? "red" : ("blue" as TeamSide);
|
||
const leaderName =
|
||
goldDiff === 0
|
||
? "동률"
|
||
: getTeamName(
|
||
detail,
|
||
leaderSide === "blue" ? blueTeam.teamIndex : redTeam.teamIndex,
|
||
);
|
||
|
||
return (
|
||
<div className="border-t border-base-content/8 bg-base-content/[0.01] px-4 py-3">
|
||
<div className="grid gap-3 md:grid-cols-[minmax(0,1fr)_11rem_minmax(0,1fr)] md:items-center">
|
||
<div className="min-w-0 text-win">
|
||
<div className="flex items-center justify-between gap-3 text-xs font-black">
|
||
<span className="truncate">
|
||
{getTeamName(detail, blueTeam.teamIndex)}
|
||
</span>
|
||
<span className="tabular-nums">
|
||
{formatNumber(blueTotals.gold)}
|
||
</span>
|
||
</div>
|
||
<div className="mt-1 h-1.5 bg-base-content/8">
|
||
<div
|
||
className="h-full bg-win"
|
||
style={{ width: barWidth(blueTotals.gold, maxGold) }}
|
||
/>
|
||
</div>
|
||
</div>
|
||
<div className="text-center">
|
||
<div className="text-[10px] font-black uppercase tracking-wider text-base-content/30">
|
||
골드 차이
|
||
</div>
|
||
<div
|
||
className={`mt-1 text-lg font-black tabular-nums ${
|
||
goldDiff > 0
|
||
? "text-win"
|
||
: goldDiff < 0
|
||
? "text-loss"
|
||
: "text-base-content/55"
|
||
}`}
|
||
>
|
||
{formatSignedCompactNumber(goldDiff)}
|
||
</div>
|
||
<div className="mt-0.5 truncate text-[11px] font-bold text-base-content/35">
|
||
{leaderName}
|
||
</div>
|
||
</div>
|
||
<div className="min-w-0 text-loss">
|
||
<div className="flex items-center justify-between gap-3 text-xs font-black">
|
||
<span className="tabular-nums">{formatNumber(redTotals.gold)}</span>
|
||
<span className="truncate text-right">
|
||
{getTeamName(detail, redTeam.teamIndex)}
|
||
</span>
|
||
</div>
|
||
<div className="mt-1 h-1.5 bg-base-content/8">
|
||
<div
|
||
className="ml-auto h-full bg-loss"
|
||
style={{ width: barWidth(redTotals.gold, maxGold) }}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
interface TimelineChartPoint {
|
||
timestamp: number;
|
||
timeLabel: string;
|
||
value: number;
|
||
positive: number;
|
||
negative: number;
|
||
blueTotal: number;
|
||
redTotal: number;
|
||
leaderSide: TeamSide | null;
|
||
}
|
||
|
||
function TimelineTooltip({
|
||
active,
|
||
payload,
|
||
blueTeamName,
|
||
redTeamName,
|
||
metricLabel,
|
||
}: {
|
||
active?: boolean;
|
||
payload?: Array<{ payload: TimelineChartPoint }>;
|
||
blueTeamName: string;
|
||
redTeamName: string;
|
||
metricLabel: string;
|
||
}) {
|
||
const point = payload?.[0]?.payload;
|
||
if (!active || !point) return null;
|
||
const leaderName =
|
||
point.leaderSide === "blue"
|
||
? blueTeamName
|
||
: point.leaderSide === "red"
|
||
? redTeamName
|
||
: "동률";
|
||
|
||
return (
|
||
<div className="border border-base-content/10 bg-base-100 px-3 py-2 text-xs shadow-lg">
|
||
<div className="font-black text-base-content">{point.timeLabel}</div>
|
||
<div className="mt-1 font-bold text-base-content/55">
|
||
{leaderName} {formatSignedCompactNumber(point.value)}
|
||
</div>
|
||
<div className="mt-2 grid grid-cols-2 gap-3 tabular-nums">
|
||
<div className="text-win">
|
||
{blueTeamName}
|
||
<span className="block font-black">
|
||
{formatNumber(point.blueTotal)}
|
||
</span>
|
||
</div>
|
||
<div className="text-loss">
|
||
{redTeamName}
|
||
<span className="block font-black">
|
||
{formatNumber(point.redTotal)}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
<div className="mt-1 text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||
{metricLabel}
|
||
</div>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
function timelineEventKey(event: NormalizedTimelineEvent, index: number) {
|
||
return [
|
||
event.timestamp,
|
||
event.side ?? "unknown",
|
||
event.type,
|
||
event.killerParticipantId ?? "none",
|
||
event.victimParticipantId ?? "none",
|
||
index,
|
||
].join(":");
|
||
}
|
||
|
||
function timelineParticipantLabel(
|
||
participant: MatchGameParticipant | undefined,
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"],
|
||
) {
|
||
if (!participant) return null;
|
||
const championName =
|
||
championDisplayName(manifest, participant.championId) ??
|
||
String(participant.championId);
|
||
return `${participant.summonerName} (${championName})`;
|
||
}
|
||
|
||
function timelineEventActors(
|
||
event: NormalizedTimelineEvent,
|
||
participantById: ReadonlyMap<number, MatchGameParticipant>,
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"],
|
||
) {
|
||
const killer = timelineParticipantLabel(
|
||
event.killerParticipantId === undefined
|
||
? undefined
|
||
: participantById.get(event.killerParticipantId),
|
||
manifest,
|
||
);
|
||
const victim = timelineParticipantLabel(
|
||
event.victimParticipantId === undefined
|
||
? undefined
|
||
: participantById.get(event.victimParticipantId),
|
||
manifest,
|
||
);
|
||
const assistants = (event.assistingParticipantIds ?? [])
|
||
.map((participantId) =>
|
||
timelineParticipantLabel(participantById.get(participantId), manifest),
|
||
)
|
||
.filter((label): label is string => Boolean(label));
|
||
const assistLabel =
|
||
assistants.length > 0 ? ` · 도움 ${assistants.join(", ")}` : "";
|
||
|
||
if (event.type === "championKill") {
|
||
if (killer && victim) return `${killer} → ${victim}${assistLabel}`;
|
||
if (killer) return `${killer} 처치${assistLabel}`;
|
||
if (victim) return `${victim} 사망`;
|
||
}
|
||
if (killer) return `${killer} 기여${assistLabel}`;
|
||
return null;
|
||
}
|
||
|
||
function TimelineGraph({
|
||
selectedGame,
|
||
detail,
|
||
manifest,
|
||
}: {
|
||
selectedGame: MatchGameDetail;
|
||
detail: ApiInternalMatchDetailResponse;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
}) {
|
||
const [metric, setMetric] = useState<TimelineMetric>("gold");
|
||
const [eventFilter, setEventFilter] = useState<TimelineEventFilter>("all");
|
||
const [selectedEventKey, setSelectedEventKey] = useState<string | null>(null);
|
||
const blueTeam = selectedGame.teams.find((team) => team.side === "blue");
|
||
const redTeam = selectedGame.teams.find((team) => team.side === "red");
|
||
const blueTeamName = blueTeam
|
||
? getTeamName(detail, blueTeam.teamIndex)
|
||
: "BLUE";
|
||
const redTeamName = redTeam ? getTeamName(detail, redTeam.teamIndex) : "RED";
|
||
const metricLabel = metric === "gold" ? "골드" : "경험치";
|
||
const chartData: TimelineChartPoint[] = (selectedGame.timeline ?? []).map(
|
||
(point) => {
|
||
const value = metric === "gold" ? point.goldDiff : point.xpDiff;
|
||
return {
|
||
timestamp: point.timestamp,
|
||
timeLabel: formatDuration(point.timestamp),
|
||
value,
|
||
positive: Math.max(value, 0),
|
||
negative: Math.min(value, 0),
|
||
blueTotal: metric === "gold" ? point.blue.gold : point.blue.xp,
|
||
redTotal: metric === "gold" ? point.red.gold : point.red.xp,
|
||
leaderSide: value > 0 ? "blue" : value < 0 ? "red" : null,
|
||
};
|
||
},
|
||
);
|
||
const maxAbs = Math.max(
|
||
1,
|
||
...chartData.map((point) => Math.abs(point.value)),
|
||
);
|
||
const finalPoint = chartData[chartData.length - 1];
|
||
const timelineEvents = normalizeTimelineEvents(
|
||
selectTimelineEventSource(
|
||
selectedGame.timelineEvents,
|
||
selectedGame.objectiveEvents ?? [],
|
||
),
|
||
);
|
||
const visibleEvents = filterTimelineEvents(timelineEvents, eventFilter);
|
||
const visibleEventEntries = visibleEvents.map((event) => {
|
||
const index = timelineEvents.indexOf(event);
|
||
return {
|
||
event,
|
||
key: timelineEventKey(event, index),
|
||
};
|
||
});
|
||
const selectedEvent = visibleEventEntries.find(
|
||
(entry) => entry.key === selectedEventKey,
|
||
);
|
||
const selectedTimestamp = selectedEvent?.event.timestamp ?? null;
|
||
const timelineMarkers = projectTimelineEventMarkers(
|
||
visibleEventEntries.map(({ event, key }) => ({ ...event, eventKey: key })),
|
||
chartData,
|
||
);
|
||
const participantById = new Map<number, MatchGameParticipant>();
|
||
for (const team of selectedGame.teams) {
|
||
for (const participant of team.participants) {
|
||
if (participant.participantId !== undefined) {
|
||
participantById.set(participant.participantId, participant);
|
||
}
|
||
}
|
||
}
|
||
const chartMaxTimestamp = Math.max(
|
||
selectedGame.gameDuration,
|
||
finalPoint?.timestamp ?? 0,
|
||
timelineEvents[timelineEvents.length - 1]?.timestamp ?? 0,
|
||
);
|
||
const finalLeader =
|
||
finalPoint?.leaderSide === "blue"
|
||
? blueTeamName
|
||
: finalPoint?.leaderSide === "red"
|
||
? redTeamName
|
||
: "동률";
|
||
|
||
return (
|
||
<section className="mt-5 overflow-hidden border border-base-content/10 bg-base-100">
|
||
<div className="flex flex-col gap-3 border-b border-base-content/8 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
|
||
<div>
|
||
<h2 className="text-sm font-black text-base-content">경기 흐름</h2>
|
||
<div className="mt-1 text-xs font-bold text-base-content/35">
|
||
{finalPoint
|
||
? `${finalLeader} ${formatSignedCompactNumber(finalPoint.value)}`
|
||
: "타임라인 대기"}
|
||
</div>
|
||
</div>
|
||
<div
|
||
className="flex w-full border border-base-content/10 bg-base-content/[0.02] sm:w-auto"
|
||
role="group"
|
||
aria-label="경기 흐름 지표"
|
||
>
|
||
{TIMELINE_METRICS.map((item) => (
|
||
<button
|
||
key={item.id}
|
||
type="button"
|
||
aria-pressed={metric === item.id}
|
||
onClick={() => setMetric(item.id)}
|
||
className={`min-w-24 flex-1 border-r border-base-content/8 px-4 py-2 text-xs font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary sm:flex-none ${
|
||
metric === item.id
|
||
? "bg-primary text-primary-content"
|
||
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
|
||
}`}
|
||
>
|
||
{item.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
</div>
|
||
{chartData.length > 0 ? (
|
||
<div className="px-2 py-4 sm:px-4">
|
||
<div className="h-[260px] min-w-0 w-full">
|
||
<ResponsiveContainer
|
||
width="100%"
|
||
height="100%"
|
||
initialDimension={{ width: 800, height: 260 }}
|
||
>
|
||
<AreaChart
|
||
data={chartData}
|
||
margin={{ top: 12, right: 12, bottom: 0, left: 0 }}
|
||
>
|
||
<CartesianGrid
|
||
stroke="currentColor"
|
||
strokeOpacity={0.08}
|
||
vertical={false}
|
||
/>
|
||
<XAxis
|
||
dataKey="timestamp"
|
||
type="number"
|
||
domain={[0, chartMaxTimestamp]}
|
||
minTickGap={28}
|
||
tickFormatter={(value) =>
|
||
`${Math.round(Number(value) / 60)}분`
|
||
}
|
||
tick={{ fill: "currentColor", fontSize: 11 }}
|
||
tickLine={false}
|
||
axisLine={false}
|
||
/>
|
||
<YAxis
|
||
domain={[-maxAbs, maxAbs]}
|
||
tickFormatter={(value) =>
|
||
formatSignedCompactNumber(Number(value))
|
||
}
|
||
tick={{ fill: "currentColor", fontSize: 11 }}
|
||
tickLine={false}
|
||
axisLine={false}
|
||
width={58}
|
||
/>
|
||
<Tooltip
|
||
content={
|
||
<TimelineTooltip
|
||
blueTeamName={blueTeamName}
|
||
redTeamName={redTeamName}
|
||
metricLabel={metricLabel}
|
||
/>
|
||
}
|
||
/>
|
||
<ReferenceLine
|
||
y={0}
|
||
stroke="currentColor"
|
||
strokeOpacity={0.25}
|
||
/>
|
||
{selectedTimestamp !== null ? (
|
||
<ReferenceLine
|
||
x={selectedTimestamp}
|
||
stroke="currentColor"
|
||
strokeDasharray="3 3"
|
||
strokeOpacity={0.35}
|
||
/>
|
||
) : null}
|
||
<Area
|
||
type="monotone"
|
||
dataKey="positive"
|
||
stroke="none"
|
||
fill="#3b82f6"
|
||
fillOpacity={0.16}
|
||
isAnimationActive={false}
|
||
/>
|
||
<Area
|
||
type="monotone"
|
||
dataKey="negative"
|
||
stroke="none"
|
||
fill="#ef4444"
|
||
fillOpacity={0.16}
|
||
isAnimationActive={false}
|
||
/>
|
||
<Line
|
||
type="monotone"
|
||
dataKey="value"
|
||
stroke="var(--color-primary)"
|
||
strokeWidth={2}
|
||
dot={false}
|
||
activeDot={{
|
||
r: 4,
|
||
fill: "var(--color-primary)",
|
||
stroke: "none",
|
||
}}
|
||
isAnimationActive={false}
|
||
/>
|
||
{timelineMarkers.map((event) => {
|
||
const selected = event.eventKey === selectedEventKey;
|
||
const markerRadius =
|
||
event.category === "objective"
|
||
? 4
|
||
: event.category === "structure"
|
||
? 3.5
|
||
: 2.5;
|
||
return (
|
||
<ReferenceDot
|
||
key={event.eventKey}
|
||
x={event.timestamp}
|
||
y={event.value}
|
||
r={selected ? 5.5 : markerRadius}
|
||
fill={
|
||
event.side === "blue"
|
||
? "#3b82f6"
|
||
: event.side === "red"
|
||
? "#ef4444"
|
||
: "currentColor"
|
||
}
|
||
stroke="currentColor"
|
||
strokeWidth={selected ? 2 : 1}
|
||
ifOverflow="extendDomain"
|
||
label={
|
||
selected
|
||
? {
|
||
value: event.markerLabel,
|
||
position: "top",
|
||
fontSize: 10,
|
||
fontWeight: 800,
|
||
fill: "currentColor",
|
||
}
|
||
: undefined
|
||
}
|
||
/>
|
||
);
|
||
})}
|
||
</AreaChart>
|
||
</ResponsiveContainer>
|
||
</div>
|
||
<div className="mt-2 flex items-center justify-between gap-3 text-[11px] font-black uppercase tracking-wider">
|
||
<span className="text-win">{blueTeamName}</span>
|
||
<span className="text-base-content/25">0</span>
|
||
<span className="text-loss">{redTeamName}</span>
|
||
</div>
|
||
</div>
|
||
) : (
|
||
<div className="px-4 py-12 text-center text-sm font-bold text-base-content/35">
|
||
타임라인 데이터가 아직 없습니다
|
||
</div>
|
||
)}
|
||
{timelineEvents.length > 0 ? (
|
||
<div className="border-t border-base-content/8 px-4 py-3">
|
||
<div className="flex flex-wrap items-baseline justify-between gap-2">
|
||
<h3 className="text-xs font-black text-base-content">주요 사건</h3>
|
||
<p className="text-[11px] font-bold text-base-content/30">
|
||
항목을 선택하면 그래프의 해당 시점을 강조합니다
|
||
</p>
|
||
</div>
|
||
<div
|
||
className="mt-3 flex w-full overflow-x-auto border border-base-content/10 bg-base-content/[0.02] sm:w-fit"
|
||
role="group"
|
||
aria-label="사건 유형 필터"
|
||
>
|
||
{TIMELINE_EVENT_FILTERS.map((filter) => (
|
||
<button
|
||
key={filter.id}
|
||
type="button"
|
||
aria-pressed={eventFilter === filter.id}
|
||
onClick={() => setEventFilter(filter.id)}
|
||
className={`min-w-20 flex-1 border-r border-base-content/8 px-3 py-2 text-[11px] font-black transition-colors last:border-r-0 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary sm:flex-none ${
|
||
eventFilter === filter.id
|
||
? "bg-primary text-primary-content"
|
||
: "text-base-content/45 hover:bg-base-content/[0.03] hover:text-base-content"
|
||
}`}
|
||
>
|
||
{filter.label}
|
||
</button>
|
||
))}
|
||
</div>
|
||
<ul
|
||
className="m-0 mt-3 grid max-h-64 list-none gap-1.5 overflow-y-auto p-0 sm:grid-cols-2 lg:grid-cols-3"
|
||
aria-label="시간순 주요 사건"
|
||
>
|
||
{visibleEventEntries.map(({ event, key }) => {
|
||
const selected = key === selectedEventKey;
|
||
const teamName =
|
||
event.side === "blue"
|
||
? blueTeamName
|
||
: event.side === "red"
|
||
? redTeamName
|
||
: null;
|
||
const actorLabel = timelineEventActors(
|
||
event,
|
||
participantById,
|
||
manifest,
|
||
);
|
||
return (
|
||
<li key={key} className="min-w-0">
|
||
<button
|
||
type="button"
|
||
aria-pressed={selected}
|
||
onClick={() => setSelectedEventKey(selected ? null : key)}
|
||
className={`grid h-full w-full grid-cols-[3.25rem_3.25rem_minmax(0,1fr)] items-start gap-2 border px-2.5 py-2 text-left text-xs transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary ${
|
||
selected
|
||
? "border-primary bg-primary/8"
|
||
: "border-base-content/8 hover:bg-base-content/[0.03]"
|
||
}`}
|
||
>
|
||
<span className="font-mono font-black tabular-nums text-base-content/55">
|
||
{formatDuration(event.timestamp)}
|
||
</span>
|
||
<span
|
||
className={`text-[10px] font-black uppercase tracking-wider ${
|
||
event.side === "blue"
|
||
? "text-win"
|
||
: event.side === "red"
|
||
? "text-loss"
|
||
: "text-base-content/35"
|
||
}`}
|
||
>
|
||
{event.side ? sideLabel(event.side) : "-"}
|
||
</span>
|
||
<span className="min-w-0">
|
||
<span className="block truncate font-bold text-base-content/75">
|
||
{teamName ? (
|
||
<span className="sr-only">{teamName} </span>
|
||
) : null}
|
||
{event.label}
|
||
</span>
|
||
{actorLabel ? (
|
||
<span
|
||
className="mt-0.5 block truncate text-[10px] font-bold text-base-content/35"
|
||
title={actorLabel}
|
||
>
|
||
{actorLabel}
|
||
</span>
|
||
) : null}
|
||
</span>
|
||
</button>
|
||
</li>
|
||
);
|
||
})}
|
||
</ul>
|
||
{visibleEventEntries.length === 0 ? (
|
||
<p className="py-6 text-center text-xs font-bold text-base-content/35">
|
||
이 유형의 사건이 없습니다
|
||
</p>
|
||
) : null}
|
||
</div>
|
||
) : null}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function TeamTable({
|
||
team,
|
||
detail,
|
||
manifest,
|
||
}: {
|
||
team: MatchGameTeam;
|
||
detail: ApiInternalMatchDetailResponse;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
}) {
|
||
const teamDamageTaken = teamTotals(team).damageTaken;
|
||
|
||
return (
|
||
<section className="overflow-hidden border border-base-content/10 bg-base-100">
|
||
<TeamScoreHeader team={team} detail={detail} />
|
||
<div className="divide-y divide-base-content/5 lg:hidden">
|
||
{team.participants.map((participant) => (
|
||
<PlayerCard
|
||
key={`card-${participant.side}-${participant.userId ?? participant.summonerName}-${participant.championId}`}
|
||
participant={participant}
|
||
manifest={manifest}
|
||
teamDamageTaken={teamDamageTaken}
|
||
/>
|
||
))}
|
||
</div>
|
||
<div className="hidden overflow-x-auto lg:block">
|
||
<table className="w-full min-w-[1040px] table-fixed text-left">
|
||
<thead>
|
||
<tr className="bg-base-content/[0.02] text-xs uppercase tracking-wider text-base-content/35">
|
||
<th className="w-[276px] px-3 py-2.5">선수</th>
|
||
<th className="w-[108px] px-3 py-2.5 text-center">KDA</th>
|
||
<th className="w-[120px] px-3 py-2.5 text-center">가한 피해량</th>
|
||
<th className="w-[120px] px-3 py-2.5 text-center">받은 피해량</th>
|
||
<th className="w-[80px] px-3 py-2.5 text-center">시야</th>
|
||
<th className="w-[96px] px-3 py-2.5 text-center">CS · 경제</th>
|
||
<th className="w-[260px] px-3 py-2.5">아이템</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
{team.participants.map((participant) => (
|
||
<PlayerRow
|
||
key={`${participant.side}-${participant.userId ?? participant.summonerName}-${participant.championId}`}
|
||
participant={participant}
|
||
manifest={manifest}
|
||
teamDamageTaken={teamDamageTaken}
|
||
/>
|
||
))}
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function ScoreboardTables({
|
||
selectedGame,
|
||
detail,
|
||
manifest,
|
||
}: {
|
||
selectedGame: MatchGameDetail;
|
||
detail: ApiInternalMatchDetailResponse;
|
||
manifest: ReturnType<typeof useDdragonManifest>["data"];
|
||
}) {
|
||
const orderedTeams = [...selectedGame.teams].sort((left, right) =>
|
||
left.side === right.side ? 0 : left.side === "blue" ? -1 : 1,
|
||
);
|
||
|
||
return (
|
||
<section className="space-y-4">
|
||
{orderedTeams.map((team) => (
|
||
<TeamTable
|
||
key={`${selectedGame.riotMatchId}-${team.side}`}
|
||
team={team}
|
||
detail={detail}
|
||
manifest={manifest}
|
||
/>
|
||
))}
|
||
</section>
|
||
);
|
||
}
|
||
|
||
function GameTabs({
|
||
detail,
|
||
groups,
|
||
group,
|
||
communityId,
|
||
currentGameNumber,
|
||
navigationState,
|
||
}: {
|
||
detail: ApiInternalMatchDetailResponse;
|
||
groups: RecordedSeries[];
|
||
group: RecordedSeries;
|
||
communityId: string;
|
||
currentGameNumber: number;
|
||
navigationState: MatchGameNavigationState | undefined;
|
||
}) {
|
||
const navigate = useNavigate();
|
||
const currentRef = useRef<HTMLAnchorElement | null>(null);
|
||
const games = group.sets.map(({ game }) => game);
|
||
const currentIndex = games.findIndex(
|
||
(game) => game.gameNumber === currentGameNumber,
|
||
);
|
||
const previousGame = games[currentIndex - 1];
|
||
const nextGame = games[currentIndex + 1];
|
||
const pathFor = (gameNumber: number) =>
|
||
internalMatchGamePath(communityId, detail.match.matchId, gameNumber);
|
||
|
||
useEffect(() => {
|
||
currentRef.current?.scrollIntoView({ block: "nearest", inline: "center" });
|
||
}, [currentGameNumber]);
|
||
|
||
const stepClass =
|
||
"grid size-10 shrink-0 place-items-center rounded-[10px] text-content-muted transition-colors hover:bg-sunken hover:text-content aria-disabled:pointer-events-none aria-disabled:opacity-30";
|
||
|
||
return (
|
||
<nav
|
||
className="lts-panel sticky top-(--app-header-height) z-30 p-1"
|
||
aria-label="세트 선택"
|
||
>
|
||
<label className="flex min-w-0 items-center gap-2 border-b border-line px-2 py-1.5 text-xs font-semibold text-content-muted">
|
||
<span className="shrink-0">대진</span>
|
||
<select
|
||
className="lts-select min-w-0"
|
||
value={group.id}
|
||
onChange={(event) => {
|
||
const next = groups.find((candidate) => candidate.id === event.target.value);
|
||
if (next) void navigate(pathFor(next.sets[0].game.gameNumber), { state: navigationState });
|
||
}}
|
||
>
|
||
{groups.map((candidate) => (
|
||
<option key={candidate.id} value={candidate.id}>{candidate.label}</option>
|
||
))}
|
||
</select>
|
||
</label>
|
||
<div className="flex items-center gap-1">
|
||
<Link
|
||
to={previousGame ? pathFor(previousGame.gameNumber) : "#"}
|
||
state={navigationState}
|
||
aria-disabled={!previousGame}
|
||
tabIndex={previousGame ? undefined : -1}
|
||
aria-label="이전 세트"
|
||
className={stepClass}
|
||
>
|
||
<ChevronLeft className="size-4" aria-hidden="true" />
|
||
</Link>
|
||
<div className="no-scrollbar flex min-w-0 flex-1 gap-1 overflow-x-auto">
|
||
{group.sets.map(({ game, official }) => {
|
||
const winnerTeam = game.teams.find((team) => team.win);
|
||
const active = game.gameNumber === currentGameNumber;
|
||
return (
|
||
<Link
|
||
key={game.gameNumber}
|
||
ref={active ? currentRef : undefined}
|
||
to={pathFor(game.gameNumber)}
|
||
state={navigationState}
|
||
aria-current={active ? "page" : undefined}
|
||
className={`flex h-10 shrink-0 items-center gap-2 rounded-[10px] px-3.5 text-sm transition-colors ${
|
||
active
|
||
? "bg-secondary text-secondary-content dark:bg-white dark:text-[#14161b]"
|
||
: "text-content-muted hover:bg-sunken hover:text-content"
|
||
}`}
|
||
>
|
||
<span className="font-bold">
|
||
{official ? `${official.ordinal}세트` : `전체 ${game.gameNumber}세트`}
|
||
</span>
|
||
{official && official.ordinal !== game.gameNumber && (
|
||
<span className="text-xs opacity-80">전체 {game.gameNumber}</span>
|
||
)}
|
||
<span
|
||
className={`max-w-28 truncate text-xs ${active ? "opacity-80" : "text-content-subtle"}`}
|
||
>
|
||
{winnerTeam
|
||
? `${getTeamName(detail, winnerTeam.teamIndex)} 승`
|
||
: "결과 대기"}
|
||
</span>
|
||
</Link>
|
||
);
|
||
})}
|
||
</div>
|
||
<Link
|
||
to={nextGame ? pathFor(nextGame.gameNumber) : "#"}
|
||
state={navigationState}
|
||
aria-disabled={!nextGame}
|
||
tabIndex={nextGame ? undefined : -1}
|
||
aria-label="다음 세트"
|
||
className={stepClass}
|
||
>
|
||
<ChevronRight className="size-4" aria-hidden="true" />
|
||
</Link>
|
||
</div>
|
||
</nav>
|
||
);
|
||
}
|
||
|
||
function MatchScoreHero({
|
||
detail,
|
||
selectedGame,
|
||
group,
|
||
backTarget,
|
||
}: {
|
||
detail: ApiInternalMatchDetailResponse;
|
||
selectedGame: MatchGameDetail;
|
||
group: RecordedSeries;
|
||
backTarget: MatchGameBackTarget;
|
||
}) {
|
||
const selectedSeries = group.series;
|
||
const officialGame = group.sets.find(({ game }) => game === selectedGame)?.official;
|
||
const setLabel = officialGame ? `${officialGame.ordinal}세트` : `전체 ${selectedGame.gameNumber}세트`;
|
||
const [leftTeam, rightTeam] = selectedGame.teams;
|
||
const getScore = (side: TeamSide) => selectedSeries?.entries.find(
|
||
(entry) => entry.teamId === officialGame?.teams[side].teamId,
|
||
)?.gameWins;
|
||
const leftScore = leftTeam && getScore(leftTeam.side);
|
||
const rightScore = rightTeam && getScore(rightTeam.side);
|
||
const showSeriesScore = selectedSeries && shouldDisplaySeriesHistoryScore(selectedSeries) && leftScore !== undefined && rightScore !== undefined;
|
||
const decision = selectedSeries?.status === "completed" ? getSeriesHistoryResultLabel(selectedSeries) : null;
|
||
const sideTone = (side: TeamSide) =>
|
||
side === "blue" ? "text-[#8fb6ff]" : "text-[#ff99a5]";
|
||
|
||
return (
|
||
<PageHero
|
||
width="xl"
|
||
crumbs={[
|
||
{ label: backTarget.label, to: backTarget.to },
|
||
{ label: setLabel },
|
||
]}
|
||
title={
|
||
<>
|
||
{detail.match.title}
|
||
<span className="ml-2 text-on-ink-muted">
|
||
{setLabel}
|
||
</span>
|
||
</>
|
||
}
|
||
meta={
|
||
<>
|
||
<span>{formatDateTime(selectedGame.gameCreation)}</span>
|
||
{officialGame && officialGame.ordinal !== selectedGame.gameNumber && (
|
||
<>
|
||
<MetaDot />
|
||
<span>전체 {selectedGame.gameNumber}세트</span>
|
||
</>
|
||
)}
|
||
<MetaDot />
|
||
<span className="tabular">
|
||
{formatDuration(selectedGame.gameDuration)}
|
||
</span>
|
||
<MetaDot />
|
||
<span className="font-mono text-xs">{selectedGame.riotMatchId}</span>
|
||
</>
|
||
}
|
||
actions={
|
||
leftTeam && rightTeam ? (
|
||
<div className="grid w-full grid-cols-[1fr_auto_1fr] items-center gap-4 sm:w-auto sm:min-w-[400px]">
|
||
<div className="min-w-0 text-right">
|
||
<div
|
||
className={`truncate text-[15px] font-bold ${leftTeam.win ? "text-on-ink" : "text-on-ink-muted"}`}
|
||
>
|
||
{getTeamName(detail, leftTeam.teamIndex)}
|
||
</div>
|
||
<div
|
||
className={`mt-0.5 text-xs font-semibold ${sideTone(leftTeam.side)}`}
|
||
>
|
||
{sideLabel(leftTeam.side)}
|
||
{leftTeam.win && " · 세트 승"}
|
||
</div>
|
||
</div>
|
||
<div className="text-center">
|
||
{showSeriesScore ? (
|
||
<>
|
||
<div className="tabular text-4xl font-extrabold">{leftScore} : {rightScore}</div>
|
||
<div className="mt-0.5 text-xs font-semibold text-on-ink-muted">
|
||
{selectedSeries.status === "in-progress" ? "시리즈 진행 스코어" : "시리즈 스코어"}
|
||
</div>
|
||
</>
|
||
) : (
|
||
<div className="text-sm font-semibold text-on-ink-muted">{decision ?? "세트 결과"}</div>
|
||
)}
|
||
</div>
|
||
<div className="min-w-0">
|
||
<div
|
||
className={`truncate text-[15px] font-bold ${rightTeam.win ? "text-on-ink" : "text-on-ink-muted"}`}
|
||
>
|
||
{getTeamName(detail, rightTeam.teamIndex)}
|
||
</div>
|
||
<div
|
||
className={`mt-0.5 text-xs font-semibold ${sideTone(rightTeam.side)}`}
|
||
>
|
||
{sideLabel(rightTeam.side)}
|
||
{rightTeam.win && " · 세트 승"}
|
||
</div>
|
||
</div>
|
||
</div>
|
||
) : undefined
|
||
}
|
||
/>
|
||
);
|
||
}
|
||
|
||
export default function MatchGameDetailPage() {
|
||
const { cid, matchId, id, gameNumber } = useParams();
|
||
const location = useLocation();
|
||
const [activeTab, setActiveTab] =
|
||
useState<InternalGameDetailTab>("scoreboard");
|
||
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
|
||
const resolvedMatchId = matchId ?? id;
|
||
const requestedGameNumber = Number(gameNumber);
|
||
const detailQuery = useInternalMatchDetail(resolvedMatchId, communityId);
|
||
const competition = useCompetition(resolvedMatchId, communityId);
|
||
const { data: ddragon } = useDdragonManifest();
|
||
const detail = detailQuery.data;
|
||
const fallbackBackTo = resolvedMatchId
|
||
? internalMatchDetailPath(communityId, resolvedMatchId)
|
||
: `/communities/${communityId}/internal-stats`;
|
||
const backTarget = resolveBackTarget(location.state, fallbackBackTo);
|
||
const navigationState = createNavigationState(backTarget, fallbackBackTo);
|
||
|
||
if (detailQuery.isLoading) {
|
||
return (
|
||
<PlainPage>
|
||
<LoadingNote label="세트 기록을 불러오는 중" />
|
||
</PlainPage>
|
||
);
|
||
}
|
||
|
||
if (detailQuery.error || !detail) {
|
||
return (
|
||
<PlainPage>
|
||
<EmptyNote
|
||
title="세트 기록을 찾을 수 없습니다"
|
||
action={<Btn to={backTarget.to}>{backTarget.label}</Btn>}
|
||
/>
|
||
</PlainPage>
|
||
);
|
||
}
|
||
|
||
const selectedGame = selectInternalMatchGame(
|
||
detail.games,
|
||
requestedGameNumber,
|
||
);
|
||
|
||
const groups = groupRecordedSets(detail, competition.data);
|
||
const group = groups.find(({ sets }) => sets.some(({ game }) => game === selectedGame));
|
||
if (!selectedGame || !group) {
|
||
const hasRecordedGames = detail.games.length > 0;
|
||
const requestedGameLabel =
|
||
Number.isSafeInteger(requestedGameNumber) && requestedGameNumber > 0
|
||
? `${requestedGameNumber}경기`
|
||
: "요청한 경기";
|
||
return (
|
||
<PlainPage>
|
||
<EmptyNote
|
||
title={
|
||
hasRecordedGames
|
||
? "해당 경기 기록을 찾을 수 없습니다"
|
||
: "수집된 세트 기록이 없습니다"
|
||
}
|
||
description={
|
||
hasRecordedGames
|
||
? `${requestedGameLabel}가 현재 상세 기록에 없습니다.`
|
||
: undefined
|
||
}
|
||
action={<Btn to={backTarget.to}>{backTarget.label}</Btn>}
|
||
/>
|
||
</PlainPage>
|
||
);
|
||
}
|
||
|
||
return (
|
||
<>
|
||
<MatchScoreHero
|
||
detail={detail}
|
||
selectedGame={selectedGame}
|
||
group={group}
|
||
backTarget={backTarget}
|
||
/>
|
||
<PageBody width="xl">
|
||
<GameTabs
|
||
detail={detail}
|
||
groups={groups}
|
||
group={group}
|
||
communityId={communityId}
|
||
currentGameNumber={selectedGame.gameNumber}
|
||
navigationState={navigationState}
|
||
/>
|
||
|
||
<PostgameBreakdown
|
||
selectedGame={selectedGame}
|
||
detail={detail}
|
||
manifest={ddragon}
|
||
/>
|
||
|
||
<TimelineGraph
|
||
key={selectedGame.riotMatchId}
|
||
selectedGame={selectedGame}
|
||
detail={detail}
|
||
manifest={ddragon}
|
||
/>
|
||
|
||
<div className="mt-5 space-y-4">
|
||
<InternalGameDetailTabBar
|
||
activeTab={activeTab}
|
||
onChange={setActiveTab}
|
||
/>
|
||
<InternalGameAnalysisPanel
|
||
activeTab={activeTab}
|
||
selectedGame={selectedGame}
|
||
detail={detail}
|
||
manifest={ddragon}
|
||
scoreboard={
|
||
<ScoreboardTables
|
||
selectedGame={selectedGame}
|
||
detail={detail}
|
||
manifest={ddragon}
|
||
/>
|
||
}
|
||
/>
|
||
</div>
|
||
</PageBody>
|
||
</>
|
||
);
|
||
}
|