1682 lines
54 KiB
TypeScript
1682 lines
54 KiB
TypeScript
import { lazy, Suspense, useState } from "react";
|
|
import { useQueryClient } from "@tanstack/react-query";
|
|
import { ArrowDown, RefreshCw, X } from "lucide-react";
|
|
import { useLocation, useParams, useSearchParams } from "react-router";
|
|
import {
|
|
Chip,
|
|
EmptyNote,
|
|
ErrorNote,
|
|
MetaDot,
|
|
PageBody,
|
|
PageHero,
|
|
Panel,
|
|
PanelHeader,
|
|
PlainPage,
|
|
} from "../ui";
|
|
import {
|
|
useChampionStats,
|
|
useDdragonManifest,
|
|
useInternalMatchDetail,
|
|
useRecentMatches,
|
|
useRecentSummary,
|
|
useRefreshUserHistory,
|
|
useUserInternalHistory,
|
|
useUserHistoryProfile,
|
|
type UserHistoryFilters,
|
|
} from "../api/hooks";
|
|
import { useRiotRefreshSocket } from "../api/useRiotRefreshSocket";
|
|
import type {
|
|
ApiChampionStatsRow,
|
|
ApiEnqueueRefreshResult,
|
|
ApiInternalMatchDetailResponse,
|
|
ApiRiotRefreshEvent,
|
|
ApiRecentMatchTeam,
|
|
ApiRecentMatchTeamParticipant,
|
|
ApiRecentMatchView,
|
|
DdragonManifest,
|
|
RiotQueueGroup,
|
|
RiotRankFilter,
|
|
} from "../api/types";
|
|
import { DEFAULT_COMMUNITY_ID } from "../config";
|
|
import { ApiError } from "../lib/api";
|
|
import {
|
|
championDisplayName,
|
|
championIconUrl,
|
|
profileIconUrl,
|
|
} from "../lib/ddragon";
|
|
import {
|
|
isRiotQueueGroup,
|
|
isRiotRankFilter,
|
|
LANE_LABELS,
|
|
QUEUE_GROUP_TABS,
|
|
RANK_FILTER_TABS,
|
|
} from "../lib/riot-history";
|
|
import {
|
|
multiKillLabel,
|
|
rankPositionRates,
|
|
} from "../lib/multi-kill";
|
|
import { ResponsiveTierLabel } from "../components/RankBadge";
|
|
import { formatRankDetail } from "../components/rankBadgeUtils";
|
|
import {
|
|
InternalGameAnalysisPanel,
|
|
InternalGameDetailTabBar,
|
|
type InternalGameDetailTab,
|
|
} from "../components/InternalGameAnalysisTabs";
|
|
import {
|
|
ItemIcon,
|
|
RuneIcon,
|
|
RuneStyleIcon,
|
|
SummonerSpellIcon,
|
|
} from "../components/ItemTooltip";
|
|
import { Btn } from "../ui/Btn";
|
|
// recharts가 무거워 메인 번들에서 분리한다 (전적 페이지에서만 로드).
|
|
const TierHistoryChart = lazy(() => import("../components/TierHistoryChart"));
|
|
|
|
type ChampionSortKey = "games" | "winRate" | "kda" | "avgCsPerMin";
|
|
|
|
type HistoryLocationState = {
|
|
backTo?: unknown;
|
|
};
|
|
|
|
function resolveBackTo(state: unknown) {
|
|
if (!state || typeof state !== "object") return "/";
|
|
const backTo = (state as HistoryLocationState).backTo;
|
|
if (
|
|
typeof backTo !== "string" ||
|
|
!backTo.startsWith("/") ||
|
|
backTo.startsWith("//")
|
|
) {
|
|
return "/";
|
|
}
|
|
return backTo;
|
|
}
|
|
|
|
function formatDuration(seconds: number) {
|
|
const minutes = Math.floor(seconds / 60);
|
|
const rest = seconds % 60;
|
|
return `${minutes}:${String(rest).padStart(2, "0")}`;
|
|
}
|
|
|
|
function formatDate(ms: number) {
|
|
return new Intl.DateTimeFormat("ko-KR", {
|
|
month: "long",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
}).format(new Date(ms));
|
|
}
|
|
|
|
function formatLastFetched(value: string | null | undefined) {
|
|
if (!value) return "저장된 갱신 시각 없음";
|
|
return new Intl.DateTimeFormat("ko-KR", {
|
|
month: "long",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
}).format(new Date(value));
|
|
}
|
|
|
|
function formatEta(seconds: number) {
|
|
if (seconds < 60) return `${Math.max(1, Math.ceil(seconds))}초`;
|
|
return `${Math.ceil(seconds / 60)}분`;
|
|
}
|
|
|
|
function formatRefreshError(error: unknown) {
|
|
if (error instanceof ApiError) {
|
|
const data = error.data;
|
|
if (
|
|
typeof data === "object" &&
|
|
data !== null &&
|
|
"retryAfterSeconds" in data &&
|
|
typeof data.retryAfterSeconds === "number"
|
|
) {
|
|
return `잠시 후 다시 시도해 주세요. 약 ${formatEta(data.retryAfterSeconds)} 뒤에 요청할 수 있습니다.`;
|
|
}
|
|
return error.message;
|
|
}
|
|
return error instanceof Error ? error.message : "갱신 요청에 실패했습니다.";
|
|
}
|
|
|
|
function ratioClass(value: number) {
|
|
if (value >= 60) return "text-loss";
|
|
if (value >= 50) return "text-win";
|
|
return "text-content-muted";
|
|
}
|
|
|
|
function kdaClass(value: number) {
|
|
if (value >= 5) return "text-gold";
|
|
if (value >= 3) return "text-leaf";
|
|
return "text-content-muted";
|
|
}
|
|
|
|
function QueueTab({
|
|
active,
|
|
children,
|
|
onClick,
|
|
}: {
|
|
active: boolean;
|
|
children: React.ReactNode;
|
|
onClick: () => void;
|
|
}) {
|
|
return (
|
|
<button
|
|
type="button"
|
|
role="tab"
|
|
aria-selected={active}
|
|
onClick={onClick}
|
|
className={`h-10 flex-none whitespace-nowrap rounded-[10px] px-4 text-sm font-bold transition-colors ${
|
|
active
|
|
? "bg-secondary text-secondary-content"
|
|
: "text-content-muted hover:bg-sunken hover:text-content"
|
|
}`}
|
|
>
|
|
{children}
|
|
</button>
|
|
);
|
|
}
|
|
|
|
function ChampionIcon({
|
|
championId,
|
|
manifest,
|
|
size = "md",
|
|
className = "",
|
|
}: {
|
|
championId: number;
|
|
manifest: DdragonManifest | null | undefined;
|
|
size?: "xs" | "sm" | "md" | "lg";
|
|
className?: string;
|
|
}) {
|
|
const iconUrl = championIconUrl(manifest, championId);
|
|
const displayName =
|
|
championDisplayName(manifest, championId) ?? String(championId);
|
|
const sizeClass =
|
|
size === "lg"
|
|
? "w-12 h-12"
|
|
: size === "sm"
|
|
? "w-5 h-5"
|
|
: size === "xs"
|
|
? "w-4 h-4"
|
|
: "w-8 h-8";
|
|
|
|
return (
|
|
<div
|
|
className={`${sizeClass} bg-base-content/10 overflow-hidden shrink-0 ${className}`}
|
|
>
|
|
{iconUrl ? (
|
|
<img
|
|
src={iconUrl}
|
|
alt={displayName}
|
|
className="w-full h-full object-cover scale-[1.18]"
|
|
loading="lazy"
|
|
/>
|
|
) : null}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function SummaryCard({
|
|
label,
|
|
value,
|
|
sub,
|
|
valueClassName = "text-content-strong",
|
|
}: {
|
|
label: string;
|
|
value: React.ReactNode;
|
|
sub?: React.ReactNode;
|
|
valueClassName?: string;
|
|
}) {
|
|
return (
|
|
<div className="px-4 py-3.5 sm:px-5">
|
|
<div className="text-xs font-semibold text-content-subtle">{label}</div>
|
|
<div
|
|
className={`tabular mt-1 text-[22px] font-extrabold leading-tight ${valueClassName}`}
|
|
>
|
|
{value}
|
|
</div>
|
|
{sub && <div className="tabular mt-0.5 text-xs text-content-muted">{sub}</div>}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function SortableHeader({
|
|
sortKey,
|
|
activeKey,
|
|
onSort,
|
|
children,
|
|
}: {
|
|
sortKey: ChampionSortKey;
|
|
activeKey: ChampionSortKey;
|
|
onSort: (key: ChampionSortKey) => void;
|
|
children: React.ReactNode;
|
|
}) {
|
|
const active = sortKey === activeKey;
|
|
return (
|
|
<th scope="col" aria-sort={active ? "descending" : "none"} className="!text-center">
|
|
<button
|
|
type="button"
|
|
onClick={() => onSort(sortKey)}
|
|
className={`inline-flex items-center gap-0.5 rounded-field px-1 py-0.5 hover:text-content ${active ? "text-content" : ""}`}
|
|
>
|
|
{children}
|
|
<ArrowDown
|
|
className={`size-3 ${active ? "opacity-100" : "opacity-0"}`}
|
|
aria-hidden="true"
|
|
/>
|
|
</button>
|
|
</th>
|
|
);
|
|
}
|
|
|
|
function ChampionStatsTable({
|
|
rows,
|
|
manifest,
|
|
selectedChampionId,
|
|
onChampionSelect,
|
|
sortKey,
|
|
onSort,
|
|
}: {
|
|
rows: ApiChampionStatsRow[];
|
|
manifest: DdragonManifest | null | undefined;
|
|
selectedChampionId?: number;
|
|
onChampionSelect: (championId: number | null) => void;
|
|
sortKey: ChampionSortKey;
|
|
onSort: (key: ChampionSortKey) => void;
|
|
}) {
|
|
if (rows.length === 0) {
|
|
return (
|
|
<div className="lts-panel px-4 py-10 text-center text-sm text-content-subtle">
|
|
조건에 맞는 챔피언 통계가 아직 없습니다.
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="lts-panel overflow-hidden">
|
|
<div className="overflow-x-auto">
|
|
<table className="lts-table min-w-[820px]">
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">챔피언</th>
|
|
<SortableHeader sortKey="winRate" activeKey={sortKey} onSort={onSort}>
|
|
승률
|
|
</SortableHeader>
|
|
<SortableHeader sortKey="games" activeKey={sortKey} onSort={onSort}>
|
|
게임
|
|
</SortableHeader>
|
|
<SortableHeader sortKey="kda" activeKey={sortKey} onSort={onSort}>
|
|
KDA
|
|
</SortableHeader>
|
|
<th scope="col" className="!text-center">평균 K / D / A</th>
|
|
<th scope="col" className="!text-center">멀티킬</th>
|
|
<SortableHeader sortKey="avgCsPerMin" activeKey={sortKey} onSort={onSort}>
|
|
CS
|
|
</SortableHeader>
|
|
<th scope="col" className="!text-right">매치</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{rows.map((row) => {
|
|
const displayName =
|
|
championDisplayName(manifest, row.championId) ??
|
|
String(row.championId);
|
|
const selected = selectedChampionId === row.championId;
|
|
const multiKills = [
|
|
["더블", row.doubleKills],
|
|
["트리플", row.tripleKills],
|
|
["쿼드라", row.quadraKills],
|
|
["펜타", row.pentaKills],
|
|
].filter(([, count]) => Number(count) > 0);
|
|
return (
|
|
<tr
|
|
key={row.championId}
|
|
className={`transition-colors hover:bg-sunken ${selected ? "bg-primary-tint/40" : ""}`}
|
|
>
|
|
<td>
|
|
<div className="flex items-center gap-2">
|
|
<ChampionIcon
|
|
championId={row.championId}
|
|
manifest={manifest}
|
|
className="rounded-full"
|
|
/>
|
|
<span className="font-bold text-content">
|
|
{displayName}
|
|
</span>
|
|
</div>
|
|
</td>
|
|
<td className="tabular w-36">
|
|
<div className="flex items-baseline justify-between gap-2">
|
|
<strong className={ratioClass(row.winRate)}>
|
|
{row.winRate}%
|
|
</strong>
|
|
<span className="whitespace-nowrap text-xs text-content-muted">
|
|
{row.wins}승 {row.losses}패
|
|
</span>
|
|
</div>
|
|
<div
|
|
className="mt-1 h-1.5 overflow-hidden rounded-full bg-loss/25"
|
|
aria-hidden="true"
|
|
>
|
|
<div
|
|
className="h-full rounded-full bg-win"
|
|
style={{ width: `${row.winRate}%` }}
|
|
/>
|
|
</div>
|
|
</td>
|
|
<td className="tabular text-center text-[13px]">
|
|
{row.games}
|
|
</td>
|
|
<td
|
|
className={`tabular text-center font-bold ${kdaClass(row.kda)}`}
|
|
>
|
|
{row.kda}
|
|
</td>
|
|
<td className="tabular whitespace-nowrap text-center text-[13px] text-content-muted">
|
|
{row.avgKills} /{" "}
|
|
<span className="text-loss">{row.avgDeaths}</span> /{" "}
|
|
{row.avgAssists}
|
|
</td>
|
|
<td className="tabular text-center text-xs text-content-muted">
|
|
{multiKills.length > 0
|
|
? multiKills
|
|
.map(([label, count]) => `${label} ${count}`)
|
|
.join(" · ")
|
|
: "—"}
|
|
</td>
|
|
<td className="tabular whitespace-nowrap text-center text-[13px]">
|
|
{row.avgCs}{" "}
|
|
<span className="text-content-muted">
|
|
({row.avgCsPerMin}/분)
|
|
</span>
|
|
</td>
|
|
<td className="text-right">
|
|
<Chip
|
|
selected={selected}
|
|
onClick={() =>
|
|
onChampionSelect(selected ? null : row.championId)
|
|
}
|
|
>
|
|
{selected ? "해제" : "보기"}
|
|
</Chip>
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function ItemSlot({
|
|
itemId,
|
|
manifest,
|
|
trinket = false,
|
|
}: {
|
|
itemId: number;
|
|
manifest: DdragonManifest | null | undefined;
|
|
trinket?: boolean;
|
|
}) {
|
|
return (
|
|
<ItemIcon
|
|
itemId={itemId}
|
|
manifest={manifest}
|
|
trinket={trinket}
|
|
className="h-6 w-6"
|
|
/>
|
|
);
|
|
}
|
|
|
|
function ItemGrid({
|
|
items,
|
|
trinket,
|
|
manifest,
|
|
itemKey,
|
|
variant = "card",
|
|
}: {
|
|
items: number[];
|
|
trinket: number;
|
|
manifest: DdragonManifest | null | undefined;
|
|
itemKey: string;
|
|
variant?: "card" | "detail";
|
|
}) {
|
|
// 6칸을 항상 채워 트링켓이 밀리지 않도록 빈 슬롯으로 패딩한다.
|
|
const coreItems = [...items.slice(0, 6)];
|
|
while (coreItems.length < 6) coreItems.push(0);
|
|
const gridCols = variant === "detail" ? "grid-cols-6" : "grid-cols-3";
|
|
|
|
return (
|
|
<div className="flex items-center gap-1.5">
|
|
<div className={`grid gap-1 ${gridCols}`}>
|
|
{coreItems.map((itemId, index) => (
|
|
<ItemSlot
|
|
key={`${itemKey}-item-${index}`}
|
|
itemId={itemId}
|
|
manifest={manifest}
|
|
/>
|
|
))}
|
|
</div>
|
|
<ItemSlot itemId={trinket} manifest={manifest} trinket />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
type MatchDetailScales = {
|
|
maxDamage: number;
|
|
};
|
|
|
|
function formatCompactNumber(value: number) {
|
|
const safeValue = Number.isFinite(value) ? value : 0;
|
|
const abs = Math.abs(safeValue);
|
|
if (abs >= 1000) {
|
|
return `${(safeValue / 1000).toFixed(1).replace(/\.0$/, "")}k`;
|
|
}
|
|
return safeValue.toLocaleString();
|
|
}
|
|
|
|
function resolveParticipantKda(participant: ApiRecentMatchTeamParticipant) {
|
|
const score = participant.kills + participant.assists;
|
|
return participant.deaths === 0
|
|
? score
|
|
: Math.round((score / participant.deaths) * 10) / 10;
|
|
}
|
|
|
|
function barPercent(value: number, max: number) {
|
|
if (!Number.isFinite(value) || !Number.isFinite(max) || max <= 0) return 0;
|
|
return Math.max(0, Math.min(100, Math.round((value / max) * 100)));
|
|
}
|
|
|
|
function LoadoutIcons({
|
|
summonerSpells,
|
|
perks,
|
|
manifest,
|
|
}: {
|
|
summonerSpells: [number, number];
|
|
perks: ApiRecentMatchTeamParticipant["perks"];
|
|
manifest: DdragonManifest | null | undefined;
|
|
}) {
|
|
return (
|
|
<div className="grid grid-cols-2 gap-0.5 shrink-0">
|
|
<SummonerSpellIcon spellId={summonerSpells[0]} manifest={manifest} />
|
|
<RuneIcon runeId={perks.keystone} manifest={manifest} />
|
|
<SummonerSpellIcon spellId={summonerSpells[1]} manifest={manifest} />
|
|
<RuneStyleIcon
|
|
styleId={perks.subStyle ?? perks.primaryStyle}
|
|
manifest={manifest}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function DetailStatBar({
|
|
label,
|
|
value,
|
|
max,
|
|
fillClass,
|
|
}: {
|
|
label: string;
|
|
value: number;
|
|
max: number;
|
|
fillClass: string;
|
|
}) {
|
|
return (
|
|
<div>
|
|
<div className="flex items-center justify-between gap-2 text-xs text-base-content/45">
|
|
<span>{label}</span>
|
|
<span className="font-bold text-base-content/70 tabular-nums">
|
|
{formatCompactNumber(value)}
|
|
</span>
|
|
</div>
|
|
<div className="mt-0.5 h-1 overflow-hidden bg-base-content/8">
|
|
<div
|
|
className={`h-full ${fillClass}`}
|
|
style={{ width: `${barPercent(value, max)}%` }}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function TeamHeader({ team }: { team: ApiRecentMatchTeam }) {
|
|
const sideLabel = team.side === 100 ? "블루팀" : "레드팀";
|
|
const sideClass = team.side === 100 ? "text-win" : "text-loss";
|
|
const resultClass = team.win ? "text-win" : "text-loss";
|
|
|
|
return (
|
|
<div className="px-3 py-1.5 flex flex-wrap items-center justify-between gap-2 border-b border-base-content/10">
|
|
<div className="flex items-center gap-2">
|
|
<span
|
|
className={`text-xs font-bold uppercase tracking-wider ${sideClass}`}
|
|
>
|
|
{sideLabel}
|
|
</span>
|
|
<span className={`text-xs font-bold ${resultClass}`}>
|
|
{team.win ? "승리" : "패배"}
|
|
</span>
|
|
</div>
|
|
<div className="flex items-center gap-3 text-xs text-base-content/45">
|
|
<span>드래곤 {team.objectives?.dragon ?? 0}</span>
|
|
<span>바론 {team.objectives?.baron ?? 0}</span>
|
|
<span>타워 {team.objectives?.tower ?? 0}</span>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function ParticipantRow({
|
|
participant,
|
|
manifest,
|
|
ownerParticipantId,
|
|
scales,
|
|
teamSide,
|
|
teamKills,
|
|
}: {
|
|
participant: ApiRecentMatchTeamParticipant;
|
|
manifest: DdragonManifest | null | undefined;
|
|
ownerParticipantId: string;
|
|
scales: MatchDetailScales;
|
|
teamSide: 100 | 200;
|
|
teamKills: number;
|
|
}) {
|
|
const championName =
|
|
championDisplayName(manifest, participant.championId) ??
|
|
String(participant.championId);
|
|
const championUrl = championIconUrl(manifest, participant.championId);
|
|
const participantName = participant.gameName || championName;
|
|
const isOwner = participant.puuid === ownerParticipantId;
|
|
const kda = resolveParticipantKda(participant);
|
|
const fillClass = teamSide === 100 ? "bg-blue-400/70" : "bg-red-400/70";
|
|
const killParticipation =
|
|
teamKills > 0
|
|
? Math.round(
|
|
((participant.kills + participant.assists) / teamKills) * 100,
|
|
)
|
|
: 0;
|
|
|
|
return (
|
|
<div
|
|
className={`grid min-w-[860px] grid-cols-[240px_92px_150px_104px_104px_196px] gap-3 items-center border-b border-base-content/5 border-l-2 px-3 py-1.5 text-xs last:border-b-0 ${
|
|
isOwner
|
|
? "border-l-primary bg-primary/[0.05]"
|
|
: "border-l-transparent hover:bg-base-content/[0.02]"
|
|
}`}
|
|
>
|
|
<div className="flex items-center gap-2 min-w-0">
|
|
<div className="relative w-9 h-9 shrink-0 overflow-hidden bg-base-content/10">
|
|
{championUrl ? (
|
|
<img
|
|
src={championUrl}
|
|
alt={championName}
|
|
className="w-full h-full object-cover scale-[1.18]"
|
|
loading="lazy"
|
|
/>
|
|
) : null}
|
|
{participant.championLevel > 0 && (
|
|
<span className="absolute bottom-0 right-0 min-w-4 bg-base-300 px-1 text-center text-xs font-bold leading-4 text-base-content">
|
|
{participant.championLevel}
|
|
</span>
|
|
)}
|
|
</div>
|
|
<div className="grid grid-cols-2 gap-0.5 shrink-0">
|
|
<SummonerSpellIcon
|
|
spellId={participant.summonerSpells[0]}
|
|
manifest={manifest}
|
|
className="h-4 w-4"
|
|
/>
|
|
<RuneIcon
|
|
runeId={participant.perks.keystone}
|
|
manifest={manifest}
|
|
className="h-4 w-4"
|
|
/>
|
|
<SummonerSpellIcon
|
|
spellId={participant.summonerSpells[1]}
|
|
manifest={manifest}
|
|
className="h-4 w-4"
|
|
/>
|
|
<RuneStyleIcon
|
|
styleId={participant.perks.subStyle ?? participant.perks.primaryStyle}
|
|
manifest={manifest}
|
|
className="h-4 w-4"
|
|
/>
|
|
</div>
|
|
<div className="min-w-0">
|
|
<div
|
|
className={`truncate font-bold ${
|
|
isOwner ? "text-primary" : "text-base-content/80"
|
|
}`}
|
|
>
|
|
{participantName}
|
|
</div>
|
|
{participant.tier && (
|
|
<div className="truncate text-xs text-content-muted"
|
|
title={`저장된 티어 · ${formatLastFetched(participant.tier.fetchedAt)}`}>
|
|
{formatRankDetail(participant.tier)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="text-center tabular-nums">
|
|
<div className="font-bold 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="mt-0.5 text-xs">
|
|
<span className={`font-bold ${kdaClass(kda)}`}>
|
|
{participant.deaths === 0 ? "Perfect" : kda}
|
|
</span>
|
|
<span className="text-base-content/35"> · {killParticipation}%</span>
|
|
</div>
|
|
</div>
|
|
|
|
<DetailStatBar
|
|
label="피해량"
|
|
value={participant.damageDealtToChampions}
|
|
max={scales.maxDamage}
|
|
fillClass={fillClass}
|
|
/>
|
|
|
|
<div className="text-xs text-base-content/45 tabular-nums">
|
|
<div className="font-bold text-base-content/70">
|
|
시야 {participant.visionScore}
|
|
</div>
|
|
<div className="mt-0.5">
|
|
와드 {participant.wardsPlaced}/{participant.wardsKilled} · 제어{" "}
|
|
{participant.controlWardsBought}
|
|
</div>
|
|
</div>
|
|
|
|
<div className="text-xs text-base-content/45 tabular-nums">
|
|
<div className="font-bold text-base-content/70">
|
|
CS {participant.totalCs}{" "}
|
|
<span className="font-normal text-base-content/40">
|
|
({participant.csPerMin}/m)
|
|
</span>
|
|
</div>
|
|
<div className="mt-0.5">
|
|
골드 {formatCompactNumber(participant.goldEarned)}
|
|
</div>
|
|
</div>
|
|
|
|
<ItemGrid
|
|
items={participant.items}
|
|
trinket={participant.trinket}
|
|
manifest={manifest}
|
|
itemKey={`${participant.puuid}-${participant.championId}`}
|
|
variant="detail"
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function MatchDetailPanel({
|
|
match,
|
|
manifest,
|
|
ownerParticipantId,
|
|
}: {
|
|
match: ApiRecentMatchView;
|
|
manifest: DdragonManifest | null | undefined;
|
|
ownerParticipantId: string;
|
|
}) {
|
|
const teams = [...match.teams].sort((left, right) => left.side - right.side);
|
|
const participants = teams.flatMap((team) => team.participants);
|
|
const scales: MatchDetailScales = {
|
|
maxDamage: Math.max(
|
|
1,
|
|
...participants.map((participant) => participant.damageDealtToChampions),
|
|
),
|
|
};
|
|
|
|
if (participants.length === 0) {
|
|
return (
|
|
<div className="p-4 text-center text-xs text-base-content/35">
|
|
이 경기의 상세 팀 데이터가 아직 없습니다.
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="p-3 sm:p-4 space-y-4">
|
|
{teams.map((team) => (
|
|
<section
|
|
key={`${match.matchId}-detail-${team.side}`}
|
|
className="overflow-hidden border border-base-content/10 bg-base-100"
|
|
>
|
|
<TeamHeader team={team} />
|
|
{(() => {
|
|
const teamKills = team.participants.reduce(
|
|
(sum, participant) => sum + participant.kills,
|
|
0,
|
|
);
|
|
return (
|
|
<div className="overflow-x-auto">
|
|
<div className="grid min-w-[860px] grid-cols-[240px_92px_150px_104px_104px_196px] gap-3 border-b border-base-content/10 bg-base-200/40 px-3 py-2 text-xs font-bold uppercase tracking-wider text-base-content/35">
|
|
<div>소환사</div>
|
|
<div className="text-center">KDA</div>
|
|
<div>피해량</div>
|
|
<div>와드</div>
|
|
<div>CS · 골드</div>
|
|
<div>아이템</div>
|
|
</div>
|
|
{team.participants.map((participant) => (
|
|
<ParticipantRow
|
|
key={`${participant.puuid}-${participant.championId}`}
|
|
participant={participant}
|
|
manifest={manifest}
|
|
ownerParticipantId={ownerParticipantId}
|
|
scales={scales}
|
|
teamSide={team.side}
|
|
teamKills={teamKills}
|
|
/>
|
|
))}
|
|
</div>
|
|
);
|
|
})()}
|
|
</section>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function resolveInternalDetailGame(
|
|
detail: ApiInternalMatchDetailResponse | undefined,
|
|
match: ApiRecentMatchView,
|
|
) {
|
|
if (!detail) return undefined;
|
|
return detail.games.find(
|
|
(game) => game.riotMatchId === match.matchId &&
|
|
(match.gameNumber === undefined || game.gameNumber === match.gameNumber),
|
|
);
|
|
}
|
|
|
|
function MatchDetailTabs({
|
|
match,
|
|
manifest,
|
|
ownerParticipantId,
|
|
}: {
|
|
match: ApiRecentMatchView;
|
|
manifest: DdragonManifest | null | undefined;
|
|
ownerParticipantId: string;
|
|
}) {
|
|
const [activeTab, setActiveTab] =
|
|
useState<InternalGameDetailTab>("scoreboard");
|
|
const hasInternalAnalysis = Boolean(match.internalMatchId);
|
|
const detailQuery = useInternalMatchDetail(
|
|
hasInternalAnalysis && activeTab !== "scoreboard"
|
|
? match.internalMatchId
|
|
: undefined,
|
|
DEFAULT_COMMUNITY_ID,
|
|
);
|
|
const selectedGame = resolveInternalDetailGame(detailQuery.data, match);
|
|
const scoreboard = (
|
|
<MatchDetailPanel
|
|
match={match}
|
|
manifest={manifest}
|
|
ownerParticipantId={ownerParticipantId}
|
|
/>
|
|
);
|
|
|
|
if (!hasInternalAnalysis) {
|
|
return scoreboard;
|
|
}
|
|
|
|
function renderTabContent() {
|
|
if (activeTab === "scoreboard") {
|
|
return scoreboard;
|
|
}
|
|
|
|
if (detailQuery.isLoading) {
|
|
return (
|
|
<div className="p-4 text-center text-xs font-bold text-base-content/35">
|
|
상세 분석 데이터를 불러오는 중...
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (detailQuery.error || !detailQuery.data || !selectedGame) {
|
|
return (
|
|
<div className="p-4 text-center text-xs font-bold text-base-content/35">
|
|
상세 분석 데이터를 불러오지 못했습니다.
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="p-3 sm:p-4">
|
|
<InternalGameAnalysisPanel
|
|
activeTab={activeTab}
|
|
selectedGame={selectedGame}
|
|
detail={detailQuery.data}
|
|
manifest={manifest}
|
|
scoreboard={scoreboard}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<div className="p-3 pb-0 sm:p-4 sm:pb-0">
|
|
<InternalGameDetailTabBar
|
|
activeTab={activeTab}
|
|
onChange={setActiveTab}
|
|
/>
|
|
</div>
|
|
{renderTabContent()}
|
|
</>
|
|
);
|
|
}
|
|
|
|
/** 접힌 행에서 양 팀 10명을 챔피언과 이름으로 훑어보게 한다. */
|
|
function MatchRoster({
|
|
teams,
|
|
manifest,
|
|
ownerParticipantId,
|
|
}: {
|
|
teams: ApiRecentMatchTeam[];
|
|
manifest: DdragonManifest | null | undefined;
|
|
ownerParticipantId: string;
|
|
}) {
|
|
if (teams.length === 0) return null;
|
|
|
|
return (
|
|
<div className="hidden w-44 shrink-0 grid-cols-2 gap-x-2 text-[11px] leading-4 lg:grid xl:w-52">
|
|
{teams.map((team) => (
|
|
<ul key={team.side} className="min-w-0 space-y-0.5">
|
|
{team.participants.map((participant) => (
|
|
<li key={participant.puuid} className="flex min-w-0 items-center gap-1">
|
|
<ChampionIcon championId={participant.championId} manifest={manifest} size="xs" className="rounded-sm" />
|
|
<span
|
|
className={`truncate ${
|
|
participant.puuid === ownerParticipantId
|
|
? "font-bold text-content"
|
|
: "text-content-muted"
|
|
}`}
|
|
title={participant.gameName}
|
|
>
|
|
{participant.gameName}
|
|
</span>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function RecentMatchCard({
|
|
match,
|
|
manifest,
|
|
ownerParticipantId,
|
|
}: {
|
|
match: ApiRecentMatchView;
|
|
manifest: DdragonManifest | null | undefined;
|
|
ownerParticipantId: string;
|
|
}) {
|
|
const multiKill = multiKillLabel(match.largestMultiKill);
|
|
const championName =
|
|
championDisplayName(manifest, match.championId) ?? String(match.championId);
|
|
const outcome = match.remake ? "remake" : match.win ? "win" : "loss";
|
|
const surface = {
|
|
win: "bg-win-tint",
|
|
loss: "bg-loss-tint",
|
|
remake: "bg-card",
|
|
}[outcome];
|
|
const bar = { win: "bg-win", loss: "bg-loss", remake: "bg-content-disabled" }[outcome];
|
|
const resultClass = {
|
|
win: "text-win",
|
|
loss: "text-loss",
|
|
remake: "text-content-muted",
|
|
}[outcome];
|
|
|
|
return (
|
|
<article className={`relative overflow-hidden rounded-box border border-line ${surface}`}>
|
|
<span aria-hidden="true" className={`absolute inset-y-0 left-0 w-1 ${bar}`} />
|
|
<div className="flex min-w-0 flex-wrap items-center gap-x-3 gap-y-2.5 py-3 pl-4 pr-2 sm:pl-5 sm:pr-3 xl:gap-x-5">
|
|
<div className="w-full shrink-0 text-xs text-content-muted sm:w-[5.5rem]">
|
|
<strong className={`block text-sm ${resultClass}`}>{match.remake ? "다시하기" : match.win ? "승리" : "패배"}</strong>
|
|
<span className="tabular sm:block">{match.queueLabel} · {formatDuration(match.gameDuration)}</span>
|
|
<span className="ml-1.5 sm:ml-0 sm:block">{formatDate(match.gameCreation)}</span>
|
|
</div>
|
|
<div className="flex min-w-0 flex-1 items-center gap-2 sm:w-40 sm:flex-none xl:w-44">
|
|
<ChampionIcon championId={match.championId} manifest={manifest} size="lg" className="rounded-xl" />
|
|
<LoadoutIcons summonerSpells={match.summonerSpells} perks={match.perks} manifest={manifest} />
|
|
<div className="min-w-0">
|
|
<div className="truncate font-bold text-content" title={championName}>{championName}</div>
|
|
<div className="text-xs text-content-muted">
|
|
{LANE_LABELS[match.teamPosition] ?? (match.teamPosition || "포지션 미확인")}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div className="tabular w-24 shrink-0 whitespace-nowrap text-right sm:text-center">
|
|
<strong className="text-sm text-content-strong sm:text-base">
|
|
{match.kills} / <span className="text-loss">{match.deaths}</span> / {match.assists}
|
|
</strong>
|
|
<div className={`text-xs font-semibold ${kdaClass(match.kda)}`}>{match.deaths === 0 ? "Perfect" : `${match.kda} KDA`}</div>
|
|
{multiKill && (
|
|
<span
|
|
className="mt-1 inline-flex h-5 items-center rounded-full border border-leaf px-2 text-[11px] font-semibold text-leaf"
|
|
>
|
|
{multiKill}
|
|
</span>
|
|
)}
|
|
</div>
|
|
<dl className="tabular hidden w-28 shrink-0 text-xs text-content-muted md:block">
|
|
<div>킬 관여 <span className="font-semibold text-content">{match.killParticipation}%</span></div>
|
|
<div>CS {match.totalCs} ({match.csPerMin}/분)</div>
|
|
<div>시야 {match.visionScore}</div>
|
|
</dl>
|
|
<div className="shrink-0">
|
|
<ItemGrid items={match.items} trinket={match.trinket} manifest={manifest} itemKey={match.matchId} />
|
|
</div>
|
|
<MatchRoster teams={match.teams} manifest={manifest} ownerParticipantId={ownerParticipantId} />
|
|
</div>
|
|
<div className="border-t border-line bg-card">
|
|
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 border-b border-line px-4 py-3 text-xs text-content-muted">
|
|
<span>Lv.{match.championLevel}</span>
|
|
<span>제어와드 {match.controlWardsBought}</span>
|
|
<span>와드 설치 {match.wardsPlaced} · 제거 {match.wardsKilled}</span>
|
|
<span>챔피언 피해량 {match.damageDealtToChampions.toLocaleString()}</span>
|
|
</div>
|
|
<MatchDetailTabs match={match} manifest={manifest} ownerParticipantId={ownerParticipantId} />
|
|
</div>
|
|
</article>
|
|
);
|
|
}
|
|
|
|
function SkeletonBlock({ className = "" }: { className?: string }) {
|
|
return <div className={`animate-pulse bg-base-content/10 ${className}`} />;
|
|
}
|
|
|
|
function MatchCardSkeleton() {
|
|
return (
|
|
<article className="space-y-2 rounded-box border border-line bg-card p-4">
|
|
<SkeletonBlock className="h-3 w-32" />
|
|
<div className="flex items-center justify-between gap-3">
|
|
<div className="flex items-center gap-2">
|
|
<SkeletonBlock className="size-9 rounded-field" />
|
|
<SkeletonBlock className="h-4 w-20" />
|
|
</div>
|
|
<SkeletonBlock className="h-4 w-16" />
|
|
</div>
|
|
</article>
|
|
);
|
|
}
|
|
|
|
function MatchListSkeleton({ count = 5 }: { count?: number }) {
|
|
return (
|
|
<div className="space-y-2">
|
|
{Array.from({ length: count }).map((_, index) => (
|
|
<MatchCardSkeleton key={index} />
|
|
))}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function HistoryPageSkeleton() {
|
|
return (
|
|
<main className="mx-auto max-w-6xl px-4 py-6 sm:px-6">
|
|
<SkeletonBlock className="mb-6 h-3 w-16" />
|
|
<section className="mb-6 border border-base-content/10 bg-base-100 p-6">
|
|
<div className="flex flex-col gap-4 sm:flex-row sm:items-center">
|
|
<SkeletonBlock className="h-16 w-16" />
|
|
<div className="flex-1 space-y-2">
|
|
<SkeletonBlock className="h-6 w-40" />
|
|
<SkeletonBlock className="h-3 w-64" />
|
|
</div>
|
|
<SkeletonBlock className="h-9 w-32" />
|
|
</div>
|
|
</section>
|
|
<div className="mb-6 grid gap-3 sm:grid-cols-2 lg:grid-cols-5">
|
|
{Array.from({ length: 5 }).map((_, index) => (
|
|
<div
|
|
key={index}
|
|
className="space-y-2 border border-base-content/8 bg-base-100 p-4"
|
|
>
|
|
<SkeletonBlock className="h-2.5 w-12" />
|
|
<SkeletonBlock className="h-7 w-16" />
|
|
<SkeletonBlock className="h-2.5 w-20" />
|
|
</div>
|
|
))}
|
|
</div>
|
|
<MatchListSkeleton />
|
|
</main>
|
|
);
|
|
}
|
|
|
|
export default function UserHistoryPage() {
|
|
const { userId } = useParams();
|
|
const location = useLocation();
|
|
const queryClient = useQueryClient();
|
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
const [backTo] = useState(() => resolveBackTo(location.state));
|
|
const [championSearch, setChampionSearch] = useState("");
|
|
const [sortKey, setSortKey] = useState<ChampionSortKey>("games");
|
|
const [refreshResult, setRefreshResult] =
|
|
useState<ApiEnqueueRefreshResult | null>(null);
|
|
const [refreshNotice, setRefreshNotice] = useState<string | null>(null);
|
|
const view = searchParams.get("view") === "champions" ? "champions" : "matches";
|
|
const queueGroupParam = searchParams.get("queueGroup");
|
|
const rankParam = searchParams.get("rank");
|
|
const queueGroup: RiotQueueGroup = isRiotQueueGroup(queueGroupParam)
|
|
? queueGroupParam
|
|
: "summoners-rift";
|
|
const isInternalQueue = queueGroup === "internal";
|
|
const rank: RiotRankFilter =
|
|
!isInternalQueue && isRiotRankFilter(rankParam) ? rankParam : "all";
|
|
const championIdParam = Number(searchParams.get("championId"));
|
|
const championId =
|
|
Number.isFinite(championIdParam) && championIdParam > 0
|
|
? championIdParam
|
|
: undefined;
|
|
const filters: UserHistoryFilters = {
|
|
queueGroup,
|
|
rank,
|
|
championId,
|
|
seasonId: searchParams.get("seasonId") ?? undefined,
|
|
};
|
|
const aggregateFilters: UserHistoryFilters = {
|
|
queueGroup,
|
|
rank,
|
|
seasonId: filters.seasonId,
|
|
};
|
|
const { data: ddragon } = useDdragonManifest();
|
|
const profileQuery = useUserHistoryProfile(userId, DEFAULT_COMMUNITY_ID);
|
|
const standardHistoryEnabled = !isInternalQueue;
|
|
const championStatsQuery = useChampionStats(
|
|
userId,
|
|
aggregateFilters,
|
|
DEFAULT_COMMUNITY_ID,
|
|
standardHistoryEnabled,
|
|
);
|
|
const summaryQuery = useRecentSummary(
|
|
userId,
|
|
filters,
|
|
DEFAULT_COMMUNITY_ID,
|
|
standardHistoryEnabled,
|
|
);
|
|
const recentMatchesQuery = useRecentMatches(
|
|
userId,
|
|
filters,
|
|
DEFAULT_COMMUNITY_ID,
|
|
standardHistoryEnabled,
|
|
);
|
|
const internalHistoryQuery = useUserInternalHistory(
|
|
userId,
|
|
filters,
|
|
DEFAULT_COMMUNITY_ID,
|
|
isInternalQueue,
|
|
);
|
|
const refreshMutation = useRefreshUserHistory(userId, DEFAULT_COMMUNITY_ID);
|
|
|
|
const profile = profileQuery.data;
|
|
const primaryTier =
|
|
profile?.tiers.find((tier) => tier.queueType === "RANKED_SOLO_5x5") ??
|
|
profile?.tiers[0];
|
|
const internalPages = internalHistoryQuery.data?.pages ?? [];
|
|
const internalFirstPage = internalPages[0];
|
|
const summary = isInternalQueue
|
|
? internalFirstPage?.summary
|
|
: summaryQuery.data;
|
|
const matches = isInternalQueue
|
|
? internalPages.flatMap((page) => page.matches)
|
|
: (recentMatchesQuery.data?.pages.flatMap((page) => page.matches) ?? []);
|
|
const historyLastFetchedAt = isInternalQueue
|
|
? internalFirstPage?.lastFetchedAt
|
|
: recentMatchesQuery.data?.pages[0]?.lastFetchedAt;
|
|
const matchesLoading = isInternalQueue
|
|
? internalHistoryQuery.isLoading
|
|
: recentMatchesQuery.isLoading;
|
|
const hasNextPage = isInternalQueue
|
|
? internalHistoryQuery.hasNextPage
|
|
: recentMatchesQuery.hasNextPage;
|
|
const isFetchingNextPage = isInternalQueue
|
|
? internalHistoryQuery.isFetchingNextPage
|
|
: recentMatchesQuery.isFetchingNextPage;
|
|
const selectedChampionName = championId
|
|
? (championDisplayName(ddragon, championId) ?? String(championId))
|
|
: null;
|
|
|
|
const positionRates = rankPositionRates(summary?.positionRates ?? {});
|
|
|
|
const visibleChampionRows = (() => {
|
|
const rows = isInternalQueue
|
|
? (internalFirstPage?.championStats.champions ?? [])
|
|
: (championStatsQuery.data?.champions ?? []);
|
|
const keyword = championSearch.trim().toLowerCase();
|
|
return rows
|
|
.filter((row) => {
|
|
if (!keyword) return true;
|
|
const displayName =
|
|
championDisplayName(ddragon, row.championId) ??
|
|
String(row.championId);
|
|
return displayName.toLowerCase().includes(keyword);
|
|
})
|
|
.sort((left, right) => right[sortKey] - left[sortKey]);
|
|
})();
|
|
|
|
const refreshSocket = useRiotRefreshSocket({
|
|
puuid: isInternalQueue ? undefined : profile?.puuid,
|
|
parentJobId: refreshResult?.parentJobId,
|
|
onEvent: (event: ApiRiotRefreshEvent) => {
|
|
if (!profile || event.puuid !== profile.puuid) return;
|
|
void invalidateHistoryQueries();
|
|
if (event.state === "completed") {
|
|
setRefreshNotice("갱신이 완료되어 전적을 다시 불러왔습니다.");
|
|
}
|
|
if (event.state === "failed") {
|
|
setRefreshNotice(
|
|
event.error
|
|
? `갱신 실패: ${event.error}`
|
|
: "갱신에 실패했습니다. 잠시 후 다시 시도해 주세요.",
|
|
);
|
|
}
|
|
},
|
|
});
|
|
|
|
function updateSearch(next: Partial<Record<string, string | number | null>>) {
|
|
const params = new URLSearchParams(searchParams);
|
|
for (const [key, value] of Object.entries(next)) {
|
|
if (value === null || value === undefined || value === "") {
|
|
params.delete(key);
|
|
} else {
|
|
params.set(key, String(value));
|
|
}
|
|
}
|
|
setSearchParams(params, { state: { backTo } });
|
|
}
|
|
|
|
async function invalidateHistoryQueries() {
|
|
await Promise.all([
|
|
queryClient.invalidateQueries({
|
|
queryKey: [
|
|
"user-history-profile",
|
|
DEFAULT_COMMUNITY_ID,
|
|
userId ?? null,
|
|
],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: ["user-champion-stats", DEFAULT_COMMUNITY_ID, userId ?? null],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: ["user-recent-summary", DEFAULT_COMMUNITY_ID, userId ?? null],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: ["user-recent-matches", DEFAULT_COMMUNITY_ID, userId ?? null],
|
|
}),
|
|
queryClient.invalidateQueries({
|
|
queryKey: [
|
|
"user-internal-history",
|
|
DEFAULT_COMMUNITY_ID,
|
|
userId ?? null,
|
|
],
|
|
}),
|
|
]);
|
|
}
|
|
|
|
function handleRefresh() {
|
|
if (!userId) return;
|
|
if (isInternalQueue) {
|
|
setRefreshResult(null);
|
|
setRefreshNotice("과거의 토너먼트 결과 수집 데이터를 다시 조회합니다.");
|
|
void queryClient.invalidateQueries({
|
|
queryKey: [
|
|
"user-internal-history",
|
|
DEFAULT_COMMUNITY_ID,
|
|
userId ?? null,
|
|
],
|
|
});
|
|
return;
|
|
}
|
|
refreshMutation.mutate(
|
|
{ queueGroups: [queueGroup], priority: "high" },
|
|
{
|
|
onSuccess: (result) => {
|
|
setRefreshResult(result);
|
|
const alreadyQueued = result.subJobs.every(
|
|
(job) => job.alreadyQueued,
|
|
);
|
|
setRefreshNotice(
|
|
alreadyQueued
|
|
? `이미 갱신 작업이 대기 중입니다. 예상 ${formatEta(result.totalEtaSeconds)} 후 반영됩니다.`
|
|
: `갱신을 요청했습니다. 예상 ${formatEta(result.totalEtaSeconds)} 후 반영됩니다.`,
|
|
);
|
|
},
|
|
onError: (error) => {
|
|
setRefreshNotice(formatRefreshError(error));
|
|
},
|
|
},
|
|
);
|
|
}
|
|
|
|
if (!DEFAULT_COMMUNITY_ID) {
|
|
return (
|
|
<main className="max-w-6xl mx-auto px-4 py-20 text-center">
|
|
<span className="text-sm text-gold">
|
|
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
|
|
</span>
|
|
</main>
|
|
);
|
|
}
|
|
|
|
if (profileQuery.isLoading) {
|
|
return <HistoryPageSkeleton />;
|
|
}
|
|
|
|
if (profileQuery.error || !profile) {
|
|
return (
|
|
<PlainPage>
|
|
<EmptyNote
|
|
title="소환사를 찾을 수 없습니다"
|
|
description="계정 연결이 해제됐거나 잘못된 주소일 수 있습니다."
|
|
action={
|
|
<Btn to="/inhouse" variant="secondary">
|
|
내전 목록으로
|
|
</Btn>
|
|
}
|
|
/>
|
|
</PlainPage>
|
|
);
|
|
}
|
|
|
|
const refreshNoticeIsError =
|
|
Boolean(refreshSocket.error) ||
|
|
Boolean(refreshNotice?.startsWith("갱신 실패"));
|
|
|
|
return (
|
|
<>
|
|
<PageHero
|
|
width="xl"
|
|
crumbs={[{ label: "이전 화면", to: backTo }, { label: "소환사 전적" }]}
|
|
media={
|
|
<div className="relative shrink-0">
|
|
<img
|
|
src={profileIconUrl(ddragon, profile.profileIconId)}
|
|
alt=""
|
|
className="size-[72px] rounded-2xl bg-ink-raised object-cover ring-2 ring-ink-line sm:size-[88px]"
|
|
/>
|
|
<span className="tabular absolute -bottom-2 left-1/2 -translate-x-1/2 rounded-full bg-ink-raised px-2 py-0.5 text-[11px] font-bold text-on-ink ring-1 ring-ink-line">
|
|
{profile.summonerLevel}
|
|
</span>
|
|
</div>
|
|
}
|
|
title={
|
|
<>
|
|
{profile.gameName}
|
|
<span className="ml-1.5 text-lg font-semibold text-on-ink-muted">
|
|
#{profile.tagLine}
|
|
</span>
|
|
</>
|
|
}
|
|
meta={
|
|
<>
|
|
<ResponsiveTierLabel tier={primaryTier} />
|
|
<MetaDot />
|
|
<span>{profile.season.label}</span>
|
|
<MetaDot />
|
|
<span>최근 갱신 {formatLastFetched(profile.lastFetchedAt)}</span>
|
|
</>
|
|
}
|
|
actions={
|
|
<Btn
|
|
variant="primary"
|
|
size="lg"
|
|
disabled={refreshMutation.isPending || !userId}
|
|
loading={refreshMutation.isPending}
|
|
icon={<RefreshCw className="size-4" aria-hidden="true" />}
|
|
onClick={handleRefresh}
|
|
>
|
|
{isInternalQueue ? "내전 기록 다시 불러오기" : "전적 갱신"}
|
|
</Btn>
|
|
}
|
|
/>
|
|
<PageBody width="xl" className="space-y-5">
|
|
{(refreshNotice || refreshSocket.error) &&
|
|
(refreshNoticeIsError ? (
|
|
<ErrorNote
|
|
title="전적을 갱신하지 못했습니다"
|
|
description={refreshNotice ?? refreshSocket.error}
|
|
/>
|
|
) : (
|
|
<div
|
|
role="status"
|
|
className="lts-panel flex items-center gap-2 px-4 py-3 text-sm text-content-muted"
|
|
>
|
|
<RefreshCw className="size-4 text-primary" aria-hidden="true" />
|
|
{refreshNotice}
|
|
</div>
|
|
))}
|
|
|
|
<div className="lts-panel sticky top-(--app-header-nav-height) z-30 p-1">
|
|
<div
|
|
className="no-scrollbar flex gap-1 overflow-x-auto"
|
|
role="tablist"
|
|
aria-label="게임 모드"
|
|
>
|
|
{QUEUE_GROUP_TABS.map((tab) => (
|
|
<QueueTab
|
|
key={tab.value}
|
|
active={queueGroup === tab.value}
|
|
onClick={() =>
|
|
updateSearch({ queueGroup: tab.value, championId: null })
|
|
}
|
|
>
|
|
{tab.label}
|
|
</QueueTab>
|
|
))}
|
|
</div>
|
|
</div>
|
|
|
|
<Panel>
|
|
<div className="flex flex-wrap items-center justify-between gap-3 border-b border-line px-4 py-3 sm:px-5">
|
|
{!isInternalQueue ? (
|
|
<div
|
|
className="flex flex-wrap gap-1.5"
|
|
role="group"
|
|
aria-label="큐 종류"
|
|
>
|
|
{RANK_FILTER_TABS.map((tab) => (
|
|
<Chip
|
|
key={tab.value}
|
|
selected={rank === tab.value}
|
|
onClick={() =>
|
|
updateSearch({ rank: tab.value, championId: null })
|
|
}
|
|
>
|
|
{tab.label}
|
|
</Chip>
|
|
))}
|
|
</div>
|
|
) : (
|
|
<p className="text-[13px] text-content-muted">
|
|
토너먼트 코드로 수집한 내전 결과만 집계합니다.
|
|
</p>
|
|
)}
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
{selectedChampionName && (
|
|
<Chip
|
|
selected
|
|
onClick={() => updateSearch({ championId: null })}
|
|
aria-label={`${selectedChampionName} 필터 해제`}
|
|
>
|
|
{selectedChampionName}
|
|
<X className="size-3.5" aria-hidden="true" />
|
|
</Chip>
|
|
)}
|
|
{profile.seasons.length > 0 && (
|
|
<select
|
|
aria-label="시즌"
|
|
value={filters.seasonId ?? profile.season.id}
|
|
onChange={(event) =>
|
|
updateSearch({
|
|
seasonId: event.target.value,
|
|
championId: null,
|
|
})
|
|
}
|
|
className="lts-select !w-auto"
|
|
>
|
|
{profile.seasons.map((season) => (
|
|
<option key={season.id} value={season.id}>
|
|
{season.label}
|
|
</option>
|
|
))}
|
|
</select>
|
|
)}
|
|
</div>
|
|
</div>
|
|
|
|
<PanelHeader
|
|
title={`최근 ${summary?.windowSize ?? 20}게임 요약`}
|
|
description={
|
|
selectedChampionName
|
|
? `${selectedChampionName} 경기만 집계`
|
|
: undefined
|
|
}
|
|
/>
|
|
<div className="grid grid-cols-2 divide-line max-lg:[&>*:nth-child(n+3)]:border-t max-lg:[&>*:nth-child(even)]:border-l lg:grid-cols-5 lg:divide-x">
|
|
<SummaryCard
|
|
label="승률"
|
|
value={summary ? `${summary.winRate}%` : "—"}
|
|
valueClassName={summary ? ratioClass(summary.winRate) : undefined}
|
|
sub={`${summary?.wins ?? 0}승 ${summary?.losses ?? 0}패`}
|
|
/>
|
|
<SummaryCard
|
|
label="KDA"
|
|
value={summary?.kda ?? "—"}
|
|
valueClassName={summary ? kdaClass(summary.kda) : undefined}
|
|
sub={`${summary?.avgKills ?? 0} / ${summary?.avgDeaths ?? 0} / ${summary?.avgAssists ?? 0}`}
|
|
/>
|
|
<SummaryCard
|
|
label="최고 평점"
|
|
value={
|
|
summary?.bestRating
|
|
? summary.bestRating.rating === "Perfect"
|
|
? "노데스"
|
|
: summary.bestRating.rating
|
|
: "—"
|
|
}
|
|
sub={
|
|
summary?.bestRating
|
|
? `${summary.bestRating.kills}/${summary.bestRating.deaths}/${summary.bestRating.assists}`
|
|
: "기록 없음"
|
|
}
|
|
/>
|
|
<SummaryCard
|
|
label="흐름"
|
|
value={
|
|
summary?.streak
|
|
? `${summary.streak.count}${summary.streak.type === "win" ? "연승" : "연패"}`
|
|
: "—"
|
|
}
|
|
valueClassName={
|
|
summary?.streak
|
|
? summary.streak.type === "win"
|
|
? "text-win"
|
|
: "text-loss"
|
|
: undefined
|
|
}
|
|
sub="가장 최근 경기 기준"
|
|
/>
|
|
<div className="px-4 py-3.5 max-lg:col-span-2 sm:px-5">
|
|
<div className="text-xs font-semibold text-content-subtle">
|
|
선호 포지션
|
|
</div>
|
|
{positionRates.length > 0 ? (
|
|
<ul className="mt-2 space-y-1.5">
|
|
{positionRates.map(({ lane, rate }) => (
|
|
<li key={lane} className="tabular text-xs">
|
|
<div className="flex justify-between gap-2">
|
|
<span className="font-semibold text-content">
|
|
{LANE_LABELS[lane] ?? lane}
|
|
</span>
|
|
<span className="text-content-muted">{rate}%</span>
|
|
</div>
|
|
<div
|
|
className="mt-0.5 h-1.5 overflow-hidden rounded-full bg-sunken-strong"
|
|
aria-hidden="true"
|
|
>
|
|
<div
|
|
className="h-full rounded-full bg-primary"
|
|
style={{ width: `${Math.min(100, rate)}%` }}
|
|
/>
|
|
</div>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
) : (
|
|
<div className="mt-2 text-xs text-content-subtle">기록 없음</div>
|
|
)}
|
|
</div>
|
|
<div className="col-span-2 border-t border-line px-4 py-3.5 max-lg:!border-l-0 sm:px-5 lg:col-span-5 lg:!border-l-0">
|
|
<div className="text-xs font-semibold text-content-subtle">
|
|
자주 플레이한 챔피언
|
|
</div>
|
|
<div className="mt-2 flex flex-wrap items-center gap-x-8 gap-y-3">
|
|
{(summary?.topChampions ?? []).map((champion) => {
|
|
const wins = Math.round(
|
|
(champion.games * champion.winRate) / 100,
|
|
);
|
|
return (
|
|
<button
|
|
type="button"
|
|
key={champion.championId}
|
|
className="group flex items-center gap-2.5 text-left"
|
|
aria-label={`${championDisplayName(ddragon, champion.championId) ?? champion.championId} 경기만 보기`}
|
|
onClick={() =>
|
|
updateSearch({ championId: champion.championId })
|
|
}
|
|
>
|
|
<ChampionIcon
|
|
championId={champion.championId}
|
|
manifest={ddragon}
|
|
size="lg"
|
|
className="rounded-full ring-2 ring-transparent transition-shadow group-hover:ring-primary"
|
|
/>
|
|
<span className="tabular">
|
|
<span
|
|
className={`block text-sm font-bold ${ratioClass(champion.winRate)}`}
|
|
>
|
|
{champion.winRate}%
|
|
<span className="ml-1.5 text-xs font-medium text-content-muted">
|
|
{wins}승 {champion.games - wins}패
|
|
</span>
|
|
</span>
|
|
<span className="block text-xs text-content-muted">
|
|
{championDisplayName(ddragon, champion.championId) ??
|
|
champion.championId}{" "}
|
|
· 평점 {champion.avgRating}
|
|
</span>
|
|
</span>
|
|
</button>
|
|
);
|
|
})}
|
|
{(summary?.topChampions ?? []).length === 0 && (
|
|
<span className="text-xs text-content-subtle">기록 없음</span>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Panel>
|
|
|
|
{profile.tierHistory.length > 0 && !isInternalQueue && (
|
|
<section className="lts-panel">
|
|
<h2 className="px-4 py-3 text-sm font-semibold">티어 그래프</h2>
|
|
<Suspense fallback={<div className="h-[180px]" />}>
|
|
<TierHistoryChart entries={profile.tierHistory} />
|
|
</Suspense>
|
|
</section>
|
|
)}
|
|
|
|
<div
|
|
className="flex items-center gap-1.5"
|
|
role="tablist"
|
|
aria-label="전적 보기"
|
|
>
|
|
<Chip
|
|
role="tab"
|
|
aria-selected={view === "matches"}
|
|
selected={view === "matches"}
|
|
onClick={() => updateSearch({ view: null })}
|
|
>
|
|
매치 히스토리
|
|
</Chip>
|
|
<Chip
|
|
role="tab"
|
|
aria-selected={view === "champions"}
|
|
selected={view === "champions"}
|
|
onClick={() => updateSearch({ view: "champions" })}
|
|
>
|
|
챔피언 통계
|
|
</Chip>
|
|
<span className="ml-auto text-xs text-content-subtle">
|
|
최근 저장 {formatLastFetched(historyLastFetchedAt)}
|
|
</span>
|
|
</div>
|
|
|
|
{view === "champions" && (
|
|
<section>
|
|
<div className="flex flex-col sm:flex-row sm:items-end sm:justify-between gap-3 mb-3">
|
|
<div>
|
|
<h2 className="sr-only">챔피언 통계</h2>
|
|
<p className="text-xs text-content-subtle">
|
|
저장된 데이터를 기준으로 집계합니다. 최신 데이터가 반영되지 않을
|
|
수 있습니다.
|
|
</p>
|
|
</div>
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<input
|
|
value={championSearch}
|
|
onChange={(event) => setChampionSearch(event.target.value)}
|
|
placeholder="챔피언 검색"
|
|
className="lts-input"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<ChampionStatsTable
|
|
rows={visibleChampionRows}
|
|
manifest={ddragon}
|
|
selectedChampionId={championId}
|
|
onChampionSelect={(nextChampionId) =>
|
|
updateSearch({ championId: nextChampionId })
|
|
}
|
|
sortKey={sortKey}
|
|
onSort={setSortKey}
|
|
/>
|
|
</section>
|
|
|
|
)}
|
|
|
|
{view === "matches" && (
|
|
<section>
|
|
<h2 className="sr-only">매치 히스토리</h2>
|
|
|
|
{matchesLoading ? (
|
|
<MatchListSkeleton />
|
|
) : matches.length === 0 ? (
|
|
<Panel>
|
|
<EmptyNote
|
|
title="조건에 맞는 경기 기록이 없습니다"
|
|
description="큐 종류나 시즌을 바꾸거나 전적을 갱신해 보세요."
|
|
/>
|
|
</Panel>
|
|
) : (
|
|
<div className="space-y-2">
|
|
{matches.map((match) => (
|
|
<RecentMatchCard
|
|
key={match.matchId}
|
|
match={match}
|
|
manifest={ddragon}
|
|
ownerParticipantId={
|
|
isInternalQueue ? profile.userId : profile.puuid
|
|
}
|
|
/>
|
|
))}
|
|
</div>
|
|
)}
|
|
|
|
{hasNextPage && (
|
|
<Btn
|
|
variant="secondary"
|
|
size="lg"
|
|
className="mt-3 w-full"
|
|
disabled={isFetchingNextPage}
|
|
loading={isFetchingNextPage}
|
|
onClick={() =>
|
|
isInternalQueue
|
|
? internalHistoryQuery.fetchNextPage()
|
|
: recentMatchesQuery.fetchNextPage()
|
|
}
|
|
>
|
|
더 보기
|
|
</Btn>
|
|
)}
|
|
</section>
|
|
)}
|
|
</PageBody>
|
|
</>
|
|
);
|
|
}
|