feat: connect tournament views to APIs and recover archived stats

Remove development previews and complete hall of fame, match history, official results, and multi-kill API integration.

Fix active match pagination and team-ready controls, preserve basic scoreboards, and recover statistics when Riot archives arrive.

Use bounded in-process cache invalidation retries and add the Riot match lookup index migration with regression coverage.
This commit is contained in:
dahyeon committed 2026-11-11 02:00:35 +09:00
1 parent 20e1e6ec04
commit 0d7617e2d2
70 files changed
+3739 -1793

No files matched your search

+82 -222
View File
@@ -1,12 +1,11 @@
import { useState } from 'react';
import type { CompetitionDetailResponse } from '@lolympus/contracts';
import { useDeferredValue, useState } from 'react';
import { ChevronDown, Search, X } from 'lucide-react';
import { Link, useLocation, useParams, useSearchParams } from 'react-router';
import {
useCommunity,
useCompetition,
useCommunityInternalStatsMatches,
useCommunityLeaderboard,
useCommunityStatsSeasons,
useDdragonManifest,
useTeamInsights,
} from '../api/hooks';
@@ -22,7 +21,7 @@ import {
profileIconUrl,
} from '../lib/ddragon';
import {
getInternalMatchOutcome,
formatOfficialMatchResult,
getMainLane,
LEADERBOARD_MIN_GAMES,
LEADERBOARD_SORTS,
@@ -38,10 +37,6 @@ import {
getHistoryMatchTitle,
getHomeMatchSchedule,
} from './home-match-presentation';
import {
getSeriesHistoryResultLabel,
shouldDisplaySeriesHistoryScore,
} from '../components/competition/competition-series-history';
import {
Btn,
Chip,
@@ -50,7 +45,6 @@ import {
LoadingNote,
Panel,
PanelHeader,
Pill,
PlainPage,
Skeleton,
} from '../ui';
@@ -95,122 +89,14 @@ function ChampionChip({
);
}
function OfficialMatchResult({
competition,
}: {
competition: CompetitionDetailResponse;
}) {
const { projection, teams } = competition;
const teamName = (id: string) =>
teams.find(({ teamId }) => teamId === id)?.name ?? '팀 미확인';
const outcome = projection.outcome;
if (projection.phase === 'cancelled') return '취소';
if (projection.phase !== 'completed' || !outcome) return '결과 확정 전';
switch (outcome.type) {
case 'double-elimination':
return `우승 · ${teamName(outcome.championTeamId)}`;
case 'round-robin':
return outcome.leaderTeamIds.length > 0
? `${outcome.leaderTeamIds.length > 1 ? '공동 1위' : '우승'} · ${outcome.leaderTeamIds.map(teamName).join(', ')}`
: '대회 종료';
case 'paired-series': {
if (projection.series.length !== 1) return '시리즈 종료';
const series = projection.series[0];
if (!shouldDisplaySeriesHistoryScore(series))
return getSeriesHistoryResultLabel(series) ?? '시리즈 종료';
const [left, right] = series.entries;
return `${teamName(left.teamId ?? '')} ${left.gameWins} : ${right.gameWins} ${teamName(right.teamId ?? '')}`;
}
}
}
/** 팀원 프로필을 겹쳐 보여주는 작은 묶음. */
function MemberStack({
members,
manifest,
}: {
members: ApiInternalMatchCard['teams'][number]['members'];
manifest: Manifest;
}) {
if (members.length === 0) return null;
return (
<span className="flex shrink-0 -space-x-1.5" aria-hidden="true">
{members.slice(0, 5).map((member) => (
<img
key={member.userId}
src={profileIconUrl(manifest, member.profileIconId)}
alt=""
title={member.summonerName}
className="size-6 rounded-full bg-sunken-strong object-cover ring-2 ring-card"
loading="lazy"
/>
))}
</span>
);
}
/** 펼치지 않아도 보이는 결과 요약. 목록 응답에 담긴 값만 쓴다. */
function MatchOutcomeSummary({
match,
recordedGameCount,
manifest,
}: {
match: ApiInternalMatchCard;
recordedGameCount: number;
manifest: Manifest;
}) {
const outcome = getInternalMatchOutcome(match);
if (!outcome) {
return (
<span className="flex items-center gap-2">
{match.status === 'in-progress' && (
<Pill tone="live" dot>
진행 중
</Pill>
)}
<span className="tabular">{recordedGameCount}세트 수집</span>
</span>
);
}
if (outcome.type === 'score') {
const { left, right, leftWins, rightWins, winner } = outcome;
const nameClass = (team: typeof left) =>
`min-w-0 truncate ${winner?.teamIndex === team.teamIndex ? 'font-bold text-content' : ''}`;
return (
<span className="flex min-w-0 items-center gap-2">
<span className={nameClass(left)}>{left.name}</span>
<strong className="tabular shrink-0 rounded-full bg-sunken-strong px-2.5 py-0.5 text-content-strong">
{leftWins} : {rightWins}
</strong>
<span className={nameClass(right)}>{right.name}</span>
</span>
);
}
return (
<span className="flex min-w-0 items-center gap-2">
<Pill tone="gold">우승</Pill>
<strong className="min-w-0 truncate font-bold text-content">
{outcome.winner.name}
</strong>
<MemberStack members={outcome.winner.members} manifest={manifest} />
</span>
);
}
function MatchCard({
match,
communityId,
manifest,
}: {
match: ApiInternalMatchCard;
communityId: string;
manifest: Manifest;
}) {
const [open, setOpen] = useState(false);
const competition = useCompetition(match.matchId, communityId, open);
const result = match.resultPresentation;
const location = useLocation();
const backTo = `${location.pathname}${location.search}`;
const recordedGames = match.games.filter(
@@ -224,10 +110,7 @@ function MatchCard({
return (
<li>
<details
className="group"
onToggle={(event) => setOpen(event.currentTarget.open)}
>
<details className="group">
<summary className="grid cursor-pointer list-none grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 gap-y-2 px-4 py-3.5 hover:bg-sunken focus-visible:-outline-offset-2 sm:grid-cols-[minmax(0,1fr)_minmax(0,18rem)_auto] sm:px-5 [&::-webkit-details-marker]:hidden">
<span className="min-w-0">
<span className="tabular block text-xs text-content-muted">
@@ -243,76 +126,62 @@ function MatchCard({
</strong>
</span>
<span className="col-start-1 row-start-2 flex min-w-0 text-sm text-content-muted sm:col-start-2 sm:row-start-1 sm:justify-end">
{competition.data ? (
<strong className="font-semibold text-content">
<OfficialMatchResult competition={competition.data} />
</strong>
) : (
<MatchOutcomeSummary
match={match}
recordedGameCount={recordedGames.length}
manifest={manifest}
/>
)}
<strong className="font-semibold text-content">
{formatOfficialMatchResult(result)}
</strong>
</span>
<ChevronDown
className="col-start-2 row-span-2 row-start-1 size-4 text-content-muted transition-transform group-open:rotate-180 sm:col-start-3 sm:row-span-1"
aria-hidden="true"
/>
</summary>
{open && (
<div className="border-t border-line bg-sunken px-4 py-3 sm:px-5">
<div className="flex flex-wrap items-center justify-between gap-2 text-sm">
<p className="text-content-muted">
{competition.isLoading
? '공식 결과를 확인하는 중'
: competition.data
? '수집된 세트 기록'
: '공식 시리즈 정보를 확인할 수 없습니다'}
</p>
<Link
className="font-semibold hover:underline"
to={internalMatchDetailPath(communityId, match.matchId)}
state={{ backTo }}
>
내전 기록 전체 보기 →
</Link>
</div>
{recordedGames.length > 0 && (
<ul className="mt-2 divide-y divide-line text-sm">
{recordedGames.map((game) => {
const winner = match.teams.find(
({ teamIndex }) => teamIndex === game.winnerTeamIndex,
);
return (
<li
key={game.gameNumber}
className="flex flex-wrap items-center justify-between gap-x-3 py-2"
>
<span className="tabular">
전체 {game.gameNumber}세트 ·{' '}
{winner ? `${winner.name} 승` : '팀 미확인'}
</span>
{game.riotMatchId && (
<Link
className="font-semibold hover:underline"
to={internalMatchGamePath(
communityId,
match.matchId,
game.gameNumber,
)}
state={{ backTo, backLabel: '내전 전적으로' }}
>
상세 분석
</Link>
)}
</li>
);
})}
</ul>
)}
<div className="border-t border-line bg-sunken px-4 py-3 sm:px-5">
<div className="flex flex-wrap items-center justify-between gap-2 text-sm">
<p className="text-content-muted">
{recordedGames.length > 0 ? '수집된 세트 기록' : '수집된 세트 기록 없음'}
</p>
<Link
className="font-semibold hover:underline"
to={internalMatchDetailPath(communityId, match.matchId)}
state={{ backTo }}
>
내전 기록 전체 보기 →
</Link>
</div>
)}
{recordedGames.length > 0 && (
<ul className="mt-2 divide-y divide-line text-sm">
{recordedGames.map((game) => {
const winner = match.teams.find(
({ teamIndex }) => teamIndex === game.winnerTeamIndex,
);
return (
<li
key={game.gameNumber}
className="flex flex-wrap items-center justify-between gap-x-3 py-2"
>
<span className="tabular">
전체 {game.gameNumber}세트 ·{' '}
{winner ? `${winner.name} 승` : '팀 미확인'}
</span>
{game.riotMatchId && (
<Link
className="font-semibold hover:underline"
to={internalMatchGamePath(
communityId,
match.matchId,
game.gameNumber,
)}
state={{ backTo, backLabel: '내전 전적으로' }}
>
상세 분석
</Link>
)}
</li>
);
})}
</ul>
)}
</div>
</details>
</li>
);
@@ -567,7 +436,7 @@ export default function CommunityInternalStatsPage() {
const isRanking = searchParams.get('view') === 'ranking';
const seasonId = searchParams.get('seasonId') || 'current';
const query = searchParams.get('q') ?? '';
const keyword = query.trim().toLocaleLowerCase('ko-KR');
const keyword = useDeferredValue(query.trim().slice(0, 100));
const format = searchParams.get('format');
const playerId = searchParams.get('player');
const sort = parseLeaderboardSort(searchParams.get('sort'));
@@ -579,12 +448,18 @@ export default function CommunityInternalStatsPage() {
limit: 12,
};
const communityQuery = useCommunity(communityId);
const seasonsQuery = useCommunityStatsSeasons(communityId);
const matchesQuery = useCommunityInternalStatsMatches(
filters,
{
...filters,
query: isRanking ? undefined : keyword,
format: format === 'pair' || format === 'tournament' ? format : undefined,
playerId: playerId ?? undefined,
},
communityId,
!isRanking,
);
const leaderboardQuery = useCommunityLeaderboard(filters, communityId);
const leaderboardQuery = useCommunityLeaderboard({ ...filters, query: isRanking ? keyword : undefined }, communityId);
const insightsQuery = useTeamInsights(filters, communityId);
const { data: ddragon } = useDdragonManifest();
const matches =
@@ -599,24 +474,12 @@ export default function CommunityInternalStatsPage() {
sort,
);
const player = leaderboardRows.find((row) => row.userId === playerId);
const visibleMatches = matches.filter((match) => {
const matchType = match.teams.length === 2 ? 'pair' : 'tournament';
return (
((format !== 'pair' && format !== 'tournament') ||
matchType === format) &&
(!playerId ||
match.teams.some((team) =>
team.members.some((member) => member.userId === playerId),
)) &&
match.title.toLocaleLowerCase('ko-KR').includes(keyword)
);
});
const visiblePlayers = leaderboardRows.filter((row) =>
row.summonerName.toLocaleLowerCase('ko-KR').includes(keyword),
);
const hasMatchFilters = Boolean(
keyword || format === 'pair' || format === 'tournament' || playerId,
);
const matchedUsers = leaderboardQuery.data?.matchedUserIds;
const visiblePlayers = isRanking && keyword
? leaderboardRows.filter((row) => matchedUsers?.includes(row.userId))
: leaderboardRows;
const hasMatchFilters = Boolean(keyword || format || playerId);
const confirmedSideWinRate = insights?.sideWinRate.confirmed;
const title = isRanking ? '선수 순위' : '최근 내전';
if (!communityId) {
@@ -673,7 +536,11 @@ export default function CommunityInternalStatsPage() {
>
<option value="current">현재 시즌</option>
<option value="all">전체 시즌</option>
{seasonId !== 'current' && seasonId !== 'all' && (
{seasonsQuery.data?.seasons
.filter(({ id }) => id !== 'current' && id !== 'all')
.map(({ id, label }) => <option key={id} value={id}>{label}</option>)}
{seasonId !== 'current' && seasonId !== 'all' &&
!seasonsQuery.data?.seasons.some(({ id }) => id === seasonId) && (
<option value={seasonId}>{season?.label ?? seasonId}</option>
)}
</select>
@@ -703,6 +570,7 @@ export default function CommunityInternalStatsPage() {
<input
type="search"
aria-label={isRanking ? '선수 검색' : '내전명 검색'}
maxLength={100}
placeholder={isRanking ? '선수 이름 검색' : '내전명 검색'}
value={query}
onChange={(event) => updateParam('q', event.target.value)}
@@ -716,7 +584,7 @@ export default function CommunityInternalStatsPage() {
<h2 id="internal-stats-heading" className="text-base font-bold">
{title}{' '}
<span className="tabular ml-1 text-sm font-medium text-content-muted">
{isRanking ? visiblePlayers.length : visibleMatches.length}
{isRanking ? visiblePlayers.length : matches.length}
</span>
</h2>
{isRanking ? (
@@ -841,34 +709,28 @@ export default function CommunityInternalStatsPage() {
}
/>
</div>
) : visibleMatches.length === 0 ? (
) : matches.length === 0 ? (
<EmptyNote
size="sm"
title={
hasMatchFilters
? '불러온 기록에 일치하는 내전이 없습니다'
? '조건에 일치하는 내전이 없습니다'
: '아직 수집된 내전 결과가 없습니다'
}
/>
) : (
<ul className="divide-y divide-line">
{visibleMatches.map((match) => (
{matches.map((match) => (
<MatchCard
key={match.matchId}
match={match}
communityId={communityId}
manifest={ddragon}
/>
))}
</ul>
)}
{matchesQuery.hasNextPage && (
<div className="space-y-2 border-t border-line p-3">
{hasMatchFilters && (
<p className="text-center text-xs text-content-muted">
필터는 불러온 {matches.length}건에 적용됩니다.
</p>
)}
{matchesQuery.isFetchNextPageError && (
<p
role="status"
@@ -901,12 +763,10 @@ export default function CommunityInternalStatsPage() {
<div className="p-4">
{insightsQuery.isLoading ? (
<Skeleton width="100%" height={52} />
) : confirmedSideWinRate ? (
<SideWinRate {...confirmedSideWinRate} />
) : insights ? (
<SideWinRate
blue={insights.sideWinRate.blue}
red={insights.sideWinRate.red}
sampleSize={insights.sideWinRate.bluePicks}
/>
<p className="text-sm text-content-muted">확정 세트 표본을 확인할 수 없습니다.</p>
) : (
<ErrorNote
title="시즌 요약을 불러오지 못했습니다"