This commit is contained in:
dahyeon committed 2026-04-27 18:55:04 -07:00
1 parent 2250b6072e
commit 1bbfc901e8
17 files changed
+3471 -59

No files matched your search

@@ -0,0 +1,388 @@
import { Link, useSearchParams } from 'react-router';
import {
useCommunity,
useCommunityInternalStatsMatches,
useCommunityLeaderboard,
useDdragonManifest,
useTeamInsights,
} from '../api/hooks';
import type {
ApiInternalMatchCard,
ApiLeaderHighlight,
ApiLeaderboardRow,
TeamSide,
} from '../api/types';
import { DEFAULT_COMMUNITY_ID } from '../config';
import { championDisplayName, championIconUrl, profileIconUrl } from '../lib/ddragon';
function formatDateTime(value: string) {
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 sideLabel(side: TeamSide) {
return side === 'blue' ? '블루팀' : '레드팀';
}
function sideText(side: TeamSide) {
return side === 'blue' ? 'text-blue-400' : 'text-red-400';
}
function ratioClass(value: number) {
if (value >= 55) return 'text-blue-400';
if (value >= 50) return 'text-amber-400';
return 'text-base-content/45';
}
function ChampionChip({
championId,
manifest,
}: {
championId: number;
manifest: ReturnType<typeof useDdragonManifest>['data'];
}) {
const icon = championIconUrl(manifest, championId);
const name = championDisplayName(manifest, championId) ?? String(championId);
return (
<span className="inline-flex items-center gap-1.5">
<span className="w-5 h-5 bg-base-content/10 overflow-hidden">
{icon ? <img src={icon} alt="" className="w-full h-full object-cover" /> : null}
</span>
<span>{name}</span>
</span>
);
}
function MatchCard({
match,
manifest,
}: {
match: ApiInternalMatchCard;
manifest: ReturnType<typeof useDdragonManifest>['data'];
}) {
return (
<Link
to={`/communities/${DEFAULT_COMMUNITY_ID}/internal-stats/match/${match.matchId}`}
className="block group"
>
<article className="border border-base-content/10 bg-base-100 hover:border-primary/25 transition-colors">
<div className="p-4 grid lg:grid-cols-[1fr_auto_1fr] gap-4 items-center">
<div className="min-w-0">
<div className="text-[11px] text-base-content/35">
{formatDateTime(match.scheduledAt)}
</div>
<h3 className="mt-1 text-base font-black text-base-content truncate group-hover:text-primary">
{match.title}
</h3>
<div className="mt-2 flex flex-wrap gap-1.5">
{match.games.map((game) => (
<span
key={game.gameNumber}
className="inline-flex items-center gap-1 border border-base-content/10 px-2 py-1 text-[10px] text-base-content/45"
>
{game.gameNumber}경기
{game.winnerSide ? (
<span className={sideText(game.winnerSide)}>
{sideLabel(game.winnerSide)} 승
</span>
) : (
'대기'
)}
<span>{formatDuration(game.gameDuration)}</span>
</span>
))}
</div>
</div>
<div className="text-center px-8">
<div className="flex items-center justify-center gap-5">
<div className={match.winnerSide === 'blue' ? 'text-blue-400' : 'text-blue-400/30'}>
<div className="text-4xl font-black tabular-nums">{match.blueScore}</div>
<div className="text-[10px] font-bold uppercase tracking-wider">BLUE</div>
</div>
<div className="text-base-content/15 text-xs font-black">VS</div>
<div className={match.winnerSide === 'red' ? 'text-red-400' : 'text-red-400/30'}>
<div className="text-4xl font-black tabular-nums">{match.redScore}</div>
<div className="text-[10px] font-bold uppercase tracking-wider">RED</div>
</div>
</div>
</div>
<div className="grid sm:grid-cols-2 gap-2">
{match.teams.map((team) => (
<div
key={team.side}
className={`border ${team.side === 'blue' ? 'border-blue-500/15' : 'border-red-500/15'} p-2`}
>
<div className={`text-[10px] font-black uppercase tracking-wider ${sideText(team.side)}`}>
{team.name}
</div>
<div className="mt-2 space-y-1">
{team.members.slice(0, 5).map((member) => (
<div key={member.userId} className="flex items-center gap-1.5 min-w-0">
<span className="w-5 h-5 bg-base-content/10 overflow-hidden shrink-0">
<img
src={profileIconUrl(manifest, member.profileIconId)}
alt=""
className="w-full h-full object-cover"
loading="lazy"
/>
</span>
<span className="text-[11px] truncate text-base-content/65">
{member.summonerName}
</span>
</div>
))}
</div>
</div>
))}
</div>
</div>
</article>
</Link>
);
}
function HighlightCard({
title,
highlight,
suffix = '',
}: {
title: string;
highlight: ApiLeaderHighlight | null | undefined;
suffix?: string;
}) {
return (
<div className="border border-base-content/10 bg-base-100 p-4">
<div className="text-[10px] font-black uppercase tracking-wider text-base-content/30">
{title}
</div>
<div className="mt-2 text-xl font-black text-base-content tabular-nums">
{highlight ? `${highlight.metric}${suffix}` : '-'}
</div>
<div className="mt-1 text-[12px] text-base-content/45">
{highlight?.summonerName ?? '기록 없음'}
</div>
</div>
);
}
function LeaderboardTable({
rows,
manifest,
}: {
rows: ApiLeaderboardRow[];
manifest: ReturnType<typeof useDdragonManifest>['data'];
}) {
return (
<div className="border border-base-content/10 bg-base-100 overflow-hidden">
<div className="overflow-x-auto">
<table className="w-full text-left min-w-[920px]">
<thead>
<tr className="border-b border-base-content/10 bg-base-200/50 text-[11px] uppercase tracking-wider text-base-content/35">
<th className="px-3 py-2.5">#</th>
<th className="px-3 py-2.5">소환사</th>
<th className="px-3 py-2.5 text-center">승률</th>
<th className="px-3 py-2.5 text-center">게임</th>
<th className="px-3 py-2.5 text-center">KDA</th>
<th className="px-3 py-2.5 text-center">GPM</th>
<th className="px-3 py-2.5 text-center">킬관여</th>
<th className="px-3 py-2.5 text-center">분당 CS</th>
<th className="px-3 py-2.5">주 챔피언</th>
</tr>
</thead>
<tbody>
{rows.map((row, index) => (
<tr key={row.userId} className="border-b border-base-content/5 last:border-b-0">
<td className="px-3 py-2.5 text-[11px] text-base-content/30">
{index + 1}
</td>
<td className="px-3 py-2.5">
<Link
to={`/users/${row.userId}/history?queueGroup=internal`}
className="flex items-center gap-2 group"
>
<span className="w-7 h-7 bg-base-content/10 overflow-hidden">
<img
src={profileIconUrl(manifest, row.profileIconId)}
alt=""
className="w-full h-full object-cover"
loading="lazy"
/>
</span>
<span className="font-bold text-[13px] group-hover:text-primary">
{row.summonerName}
</span>
</Link>
</td>
<td className={`px-3 py-2.5 text-center text-[13px] font-black ${ratioClass(row.winRate)}`}>
{row.winRate}%
</td>
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
{row.games}
</td>
<td className="px-3 py-2.5 text-center text-[12px] font-bold tabular-nums">
{row.kda}
</td>
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
{row.avgGoldPerMin}
</td>
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
{row.avgKillParticipation}%
</td>
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
{row.avgCsPerMin}
</td>
<td className="px-3 py-2.5">
<div className="flex flex-wrap gap-2 text-[11px] text-base-content/55">
{row.topChampions.map((champion) => (
<ChampionChip
key={champion.championId}
championId={champion.championId}
manifest={manifest}
/>
))}
</div>
</td>
</tr>
))}
{rows.length === 0 && (
<tr>
<td colSpan={9} className="py-10 text-center text-sm text-base-content/35">
아직 집계할 내전 기록이 없습니다.
</td>
</tr>
)}
</tbody>
</table>
</div>
</div>
);
}
export default function CommunityInternalStatsPage() {
const [searchParams] = useSearchParams();
const championIdParam = Number(searchParams.get('championId'));
const championId =
Number.isFinite(championIdParam) && championIdParam > 0
? championIdParam
: undefined;
const filters = {
seasonId: searchParams.get('seasonId') ?? undefined,
championId,
limit: 12,
};
const communityQuery = useCommunity(DEFAULT_COMMUNITY_ID);
const matchesQuery = useCommunityInternalStatsMatches(filters);
const leaderboardQuery = useCommunityLeaderboard(filters);
const insightsQuery = useTeamInsights(filters);
const { data: ddragon } = useDdragonManifest();
const matches = matchesQuery.data?.pages.flatMap((page) => page.matches) ?? [];
const season =
leaderboardQuery.data?.season ?? matchesQuery.data?.pages[0]?.season ?? null;
if (!DEFAULT_COMMUNITY_ID) {
return (
<main className="max-w-6xl mx-auto px-4 py-20 text-center text-sm text-amber-600">
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
</main>
);
}
return (
<main className="max-w-6xl mx-auto px-4 sm:px-6 py-6">
<Link to="/" className="text-xs text-base-content/40 hover:text-base-content">
← 홈으로
</Link>
<section className="mt-5 mb-6 border border-base-content/10 bg-base-100 p-5">
<div className="flex flex-col sm:flex-row sm:items-end sm:justify-between gap-4">
<div>
<p className="text-[11px] font-black uppercase tracking-[0.24em] text-primary">
Community Records
</p>
<h1 className="mt-2 text-3xl font-black text-base-content">
{communityQuery.data?.name ?? '커뮤니티'} 내전 전적
</h1>
<p className="mt-2 text-sm text-base-content/45">
토너먼트 코드로 수집된 결과를 기준으로 매치, 선수 순위, 팀 인사이트를 보여줍니다.
</p>
</div>
<div className="border border-base-content/10 px-4 py-3 text-sm text-base-content/55">
<div className="text-[10px] uppercase tracking-wider text-base-content/30">
시즌
</div>
<div className="mt-1 font-bold">{season?.label ?? '현재 시즌'}</div>
</div>
</div>
</section>
<section className="grid sm:grid-cols-2 lg:grid-cols-5 gap-3 mb-6">
<HighlightCard title="최고 KDA" highlight={insightsQuery.data?.topKda} />
<HighlightCard title="누적 킬 1위" highlight={insightsQuery.data?.mostKills} />
<HighlightCard title="단일 경기 GPM" highlight={insightsQuery.data?.topTeamGpm} />
<HighlightCard title="킬 관여율" highlight={insightsQuery.data?.topKillParticipation} suffix="%" />
<HighlightCard title="분당 CS" highlight={insightsQuery.data?.bestFarm} />
</section>
<section className="mb-8">
<div className="flex items-center justify-between gap-3 mb-3">
<h2 className="text-sm font-black text-base-content">최근 내전</h2>
<div className="text-[11px] text-base-content/35">
블루 승률 {insightsQuery.data?.sideWinRate.blue ?? 0}% · 레드 승률{' '}
{insightsQuery.data?.sideWinRate.red ?? 0}%
</div>
</div>
{matchesQuery.isLoading ? (
<div className="border border-base-content/10 bg-base-100 px-4 py-12 text-center text-sm text-base-content/35">
내전 기록을 불러오는 중...
</div>
) : (
<div className="space-y-3">
{matches.map((match) => (
<MatchCard key={match.matchId} match={match} manifest={ddragon} />
))}
{matches.length === 0 && (
<div className="border border-base-content/10 bg-base-100 px-4 py-12 text-center text-sm text-base-content/35">
아직 수집된 내전 결과가 없습니다.
</div>
)}
</div>
)}
{matchesQuery.hasNextPage && (
<button
type="button"
className="mt-3 w-full border border-base-content/15 bg-base-100 py-3 text-sm font-bold text-base-content/60 hover:text-primary hover:border-primary/30 disabled:opacity-40"
disabled={matchesQuery.isFetchingNextPage}
onClick={() => matchesQuery.fetchNextPage()}
>
{matchesQuery.isFetchingNextPage ? '불러오는 중...' : '+ 더 보기'}
</button>
)}
</section>
<section>
<div className="flex items-center justify-between gap-3 mb-3">
<h2 className="text-sm font-black text-base-content">선수 순위</h2>
<div className="text-[11px] text-base-content/35">
포지션은 Riot Match의 라인 정보를 기준으로 합니다.
</div>
</div>
<LeaderboardTable
rows={leaderboardQuery.data?.rows ?? []}
manifest={ddragon}
/>
</section>
</main>
);
}
+11 -3
View File
@@ -88,9 +88,17 @@ export default function HomePage() {
return (
<main className="max-w-5xl mx-auto px-4 sm:px-6">
<section className="pt-8 pb-6">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest mb-3">
다음 내전
</h2>
<div className="flex items-center justify-between gap-3 mb-3">
<h2 className="text-xs font-bold text-base-content/40 uppercase tracking-widest">
다음 내전
</h2>
<Link
to={`/communities/${DEFAULT_COMMUNITY_ID}/internal-stats`}
className="text-xs font-bold text-primary hover:underline"
>
내전 전적 보기
</Link>
</div>
{nextMatch ? (
<Link to={`/match/${nextMatch.id}`} className="block group">
@@ -0,0 +1,262 @@
import { Link, useParams } from 'react-router';
import { useDdragonManifest, useInternalMatchDetail } from '../api/hooks';
import type { ApiInternalMatchDetailResponse, TeamSide } from '../api/types';
import { DEFAULT_COMMUNITY_ID } from '../config';
import { championDisplayName, championIconUrl, itemIconUrl } from '../lib/ddragon';
import { LANE_LABELS } from '../lib/riot-history';
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 sideLabel(side: TeamSide) {
return side === 'blue' ? '블루팀' : '레드팀';
}
function sideClass(side: TeamSide) {
return side === 'blue' ? 'text-blue-400 border-blue-500/20' : 'text-red-400 border-red-500/20';
}
function ChampionCell({
championId,
manifest,
}: {
championId: number;
manifest: ReturnType<typeof useDdragonManifest>['data'];
}) {
const icon = championIconUrl(manifest, championId);
const name = championDisplayName(manifest, championId) ?? String(championId);
return (
<div className="flex items-center gap-2 min-w-0">
<span className="w-8 h-8 bg-base-content/10 overflow-hidden shrink-0">
{icon ? <img src={icon} alt="" className="w-full h-full object-cover" /> : null}
</span>
<span className="font-bold text-[13px] truncate">{name}</span>
</div>
);
}
function ItemStrip({
items,
trinket,
manifest,
}: {
items: number[];
trinket: number;
manifest: ReturnType<typeof useDdragonManifest>['data'];
}) {
return (
<div className="flex flex-wrap gap-1">
{[...items, trinket].map((itemId, index) => {
const icon = itemIconUrl(manifest, itemId);
return (
<span
key={`${itemId}-${index}`}
className="w-5 h-5 bg-base-content/10 border border-base-content/5 overflow-hidden"
>
{icon ? <img src={icon} alt="" className="w-full h-full object-cover" /> : null}
</span>
);
})}
</div>
);
}
function GamePanel({
game,
manifest,
}: {
game: ApiInternalMatchDetailResponse['games'][number];
manifest: ReturnType<typeof useDdragonManifest>['data'];
}) {
return (
<section className="border border-base-content/10 bg-base-100 overflow-hidden">
<div className="px-4 py-3 border-b border-base-content/10 bg-base-200/40 flex flex-wrap items-center justify-between gap-3">
<div>
<h2 className="text-sm font-black text-base-content">
{game.gameNumber}경기
</h2>
<p className="mt-1 text-[11px] text-base-content/35">
{formatDateTime(game.gameCreation)} · {formatDuration(game.gameDuration)} ·{' '}
<span className="font-mono">{game.riotMatchId}</span>
</p>
</div>
<div className="flex gap-2">
{game.teams.map((team) => (
<span
key={team.side}
className={`border px-2 py-1 text-[11px] font-black ${sideClass(team.side)} ${
team.win ? 'bg-base-content/5' : 'opacity-40'
}`}
>
{sideLabel(team.side)} {team.win ? '승' : '패'}
</span>
))}
</div>
</div>
{game.teams.map((team) => (
<div key={team.side} className="border-b border-base-content/8 last:border-b-0">
<div className={`px-4 py-2 text-[11px] font-black uppercase tracking-wider ${sideClass(team.side)}`}>
{sideLabel(team.side)} · 바론 {team.objectives.baron} · 드래곤{' '}
{team.objectives.dragon} · 타워 {team.objectives.tower}
</div>
<div className="overflow-x-auto">
<table className="w-full text-left min-w-[980px]">
<thead>
<tr className="bg-base-content/[0.02] text-[11px] text-base-content/35 uppercase tracking-wider">
<th className="px-3 py-2">소환사</th>
<th className="px-3 py-2">챔피언</th>
<th className="px-3 py-2 text-center">포지션</th>
<th className="px-3 py-2 text-center">K/D/A</th>
<th className="px-3 py-2 text-center">CS</th>
<th className="px-3 py-2 text-center">GPM</th>
<th className="px-3 py-2 text-center">킬관여</th>
<th className="px-3 py-2 text-center">피해비중</th>
<th className="px-3 py-2">아이템</th>
</tr>
</thead>
<tbody>
{team.participants.map((participant) => (
<tr
key={`${team.side}-${participant.userId}-${participant.championId}`}
className="border-t border-base-content/5"
>
<td className="px-3 py-2">
{participant.userId ? (
<Link
to={`/users/${participant.userId}/history?queueGroup=internal`}
className="font-bold text-[13px] hover:text-primary"
>
{participant.summonerName}
</Link>
) : (
<span className="font-bold text-[13px]">
{participant.summonerName}
</span>
)}
</td>
<td className="px-3 py-2">
<ChampionCell championId={participant.championId} manifest={manifest} />
</td>
<td className="px-3 py-2 text-center text-[12px]">
{LANE_LABELS[participant.teamPosition] ?? participant.teamPosition ?? '-'}
</td>
<td className="px-3 py-2 text-center text-[13px] font-black tabular-nums">
{participant.kills}
<span className="text-base-content/25"> / </span>
<span className="text-red-400">{participant.deaths}</span>
<span className="text-base-content/25"> / </span>
{participant.assists}
</td>
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
{participant.cs} ({participant.csPerMin}/m)
</td>
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
{participant.gpm}
</td>
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
{participant.killParticipation}%
</td>
<td className="px-3 py-2 text-center text-[12px] tabular-nums">
{participant.damageShare}%
</td>
<td className="px-3 py-2">
<ItemStrip
items={participant.items}
trinket={participant.trinket}
manifest={manifest}
/>
</td>
</tr>
))}
</tbody>
</table>
</div>
</div>
))}
</section>
);
}
export default function InternalMatchDetailPage() {
const { cid, matchId } = useParams();
const communityId = cid ?? DEFAULT_COMMUNITY_ID;
const detailQuery = useInternalMatchDetail(matchId, communityId);
const { data: ddragon } = useDdragonManifest();
const detail = detailQuery.data;
if (detailQuery.isLoading) {
return (
<main className="max-w-6xl mx-auto px-4 py-20 text-center text-sm text-base-content/40">
내전 상세 기록을 불러오는 중...
</main>
);
}
if (detailQuery.error || !detail) {
return (
<main className="max-w-6xl mx-auto px-4 py-20 text-center">
<h1 className="text-lg font-bold">내전 기록을 찾을 수 없습니다</h1>
<Link
to={`/communities/${communityId}/internal-stats`}
className="btn btn-ghost btn-sm mt-4"
>
내전 전적으로 돌아가기
</Link>
</main>
);
}
return (
<main className="max-w-6xl mx-auto px-4 sm:px-6 py-6">
<Link
to={`/communities/${communityId}/internal-stats`}
className="text-xs text-base-content/40 hover:text-base-content"
>
← 내전 전적
</Link>
<section className="mt-5 mb-6 border border-base-content/10 bg-base-100 p-5">
<div className="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div>
<h1 className="text-2xl font-black text-base-content">
{detail.match.title}
</h1>
<p className="mt-2 text-sm text-base-content/45">
{formatDateTime(detail.match.scheduledAt)} · {detail.match.gameCount}전제
</p>
</div>
<div className="flex items-center gap-6">
<div className={detail.match.winnerSide === 'blue' ? 'text-blue-400' : 'text-blue-400/30'}>
<div className="text-4xl font-black tabular-nums">{detail.match.blueScore}</div>
<div className="text-[10px] font-bold uppercase tracking-wider">BLUE</div>
</div>
<div className="text-base-content/15 text-xs font-black">VS</div>
<div className={detail.match.winnerSide === 'red' ? 'text-red-400' : 'text-red-400/30'}>
<div className="text-4xl font-black tabular-nums">{detail.match.redScore}</div>
<div className="text-[10px] font-bold uppercase tracking-wider">RED</div>
</div>
</div>
</div>
</section>
<div className="space-y-4">
{detail.games.map((game) => (
<GamePanel key={game.riotMatchId} game={game} manifest={ddragon} />
))}
</div>
</main>
);
}
+126 -51
View File
@@ -7,6 +7,7 @@ import {
useRecentMatches,
useRecentSummary,
useRefreshUserHistory,
useUserInternalHistory,
useUserHistoryProfile,
type UserHistoryFilters,
} from "../api/hooks";
@@ -495,7 +496,9 @@ export default function UserHistoryPage() {
const queueGroup: RiotQueueGroup = isRiotQueueGroup(queueGroupParam)
? queueGroupParam
: "summoners-rift";
const rank: RiotRankFilter = isRiotRankFilter(rankParam) ? rankParam : "all";
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
@@ -514,16 +517,30 @@ export default function UserHistoryPage() {
};
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 summaryQuery = useRecentSummary(userId, filters, DEFAULT_COMMUNITY_ID);
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);
@@ -531,14 +548,32 @@ export default function UserHistoryPage() {
const primaryTier =
profile?.tiers.find((tier) => tier.queueType === "RANKED_SOLO_5x5") ??
profile?.tiers[0];
const matches =
recentMatchesQuery.data?.pages.flatMap((page) => page.matches) ?? [];
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 visibleChampionRows = useMemo(() => {
const rows = championStatsQuery.data?.champions ?? [];
const rows = isInternalQueue
? (internalFirstPage?.championStats.champions ?? [])
: (championStatsQuery.data?.champions ?? []);
const keyword = championSearch.trim().toLowerCase();
return rows
.filter((row) => {
@@ -549,10 +584,17 @@ export default function UserHistoryPage() {
return displayName.toLowerCase().includes(keyword);
})
.sort((left, right) => right[sortKey] - left[sortKey]);
}, [championSearch, championStatsQuery.data?.champions, ddragon, sortKey]);
}, [
championSearch,
championStatsQuery.data?.champions,
ddragon,
internalFirstPage?.championStats.champions,
isInternalQueue,
sortKey,
]);
const refreshSocket = useRiotRefreshSocket({
puuid: profile?.puuid,
puuid: isInternalQueue ? undefined : profile?.puuid,
parentJobId: refreshResult?.parentJobId,
onEvent: (event: ApiRiotRefreshEvent) => {
if (!profile || event.puuid !== profile.puuid) return;
@@ -600,11 +642,24 @@ export default function UserHistoryPage() {
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(
"내전 기록은 토너먼트 결과 수집 데이터를 다시 조회합니다. Riot API 갱신 큐는 사용하지 않습니다.",
);
void queryClient.invalidateQueries({
queryKey: ["user-internal-history", DEFAULT_COMMUNITY_ID, userId ?? null],
});
return;
}
refreshMutation.mutate(
{ queueGroups: [queueGroup], priority: "high" },
{
@@ -699,10 +754,19 @@ export default function UserHistoryPage() {
</div>
<div className="border border-dashed border-base-content/10 px-3 py-2 text-[11px] text-base-content/35 sm:text-right space-y-2">
<div>
{/* 이 페이지는 저장된 경기 DB만 조회합니다. */}
<br />
{/* Riot API 갱신은 버튼 클릭 시 큐에서 처리합니다. */}
아래 버튼을 누르면 기록이 갱신됩니다.
{isInternalQueue ? (
<>
{/* 내전 탭은 토너먼트 결과 DB를 조회합니다. */}
Riot API 갱신 없이 수집된 내전 결과를 다시 불러옵니다.
</>
) : (
<>
{/* 이 페이지는 저장된 경기 DB만 조회합니다. */}
<br />
{/* Riot API 갱신은 버튼 클릭 시 큐에서 처리합니다. */}
아래 버튼을 누르면 기록이 갱신됩니다.
</>
)}
</div>
<button
type="button"
@@ -710,11 +774,17 @@ export default function UserHistoryPage() {
disabled={refreshMutation.isPending || !userId}
onClick={handleRefresh}
>
{refreshMutation.isPending ? "요청 중..." : "정보 갱신"}
{isInternalQueue
? "내전 기록 다시 불러오기"
: refreshMutation.isPending
? "요청 중..."
: "정보 갱신"}
</button>
<div className="text-[10px] text-base-content/25">
갱신 소켓: {refreshSocket.connectionStatus}
</div>
{!isInternalQueue && (
<div className="text-[10px] text-base-content/25">
갱신 소켓: {refreshSocket.connectionStatus}
</div>
)}
</div>
</div>
{(refreshNotice || refreshSocket.error) && (
@@ -739,19 +809,25 @@ export default function UserHistoryPage() {
))}
</div>
<div className="flex flex-wrap items-center justify-between gap-3 px-3 py-2">
<div className="flex flex-wrap">
{RANK_FILTER_TABS.map((tab) => (
<FilterButton
key={tab.value}
active={rank === tab.value}
onClick={() =>
updateSearch({ rank: tab.value, championId: null })
}
>
{tab.label}
</FilterButton>
))}
</div>
{!isInternalQueue ? (
<div className="flex flex-wrap">
{RANK_FILTER_TABS.map((tab) => (
<FilterButton
key={tab.value}
active={rank === tab.value}
onClick={() =>
updateSearch({ rank: tab.value, championId: null })
}
>
{tab.label}
</FilterButton>
))}
</div>
) : (
<div className="px-3 py-2 text-[11px] text-base-content/40">
내전 탭은 토너먼트 코드 결과 수집 데이터를 기준으로 집계합니다.
</div>
)}
{selectedChampionName && (
<button
type="button"
@@ -781,33 +857,33 @@ export default function UserHistoryPage() {
<section className="mb-6">
<h2 className="text-sm font-bold text-base-content mb-3">
최근 {summaryQuery.data?.windowSize ?? 20}게임 전적 요약
최근 {summary?.windowSize ?? 20}게임 전적 요약
</h2>
<div className="grid sm:grid-cols-2 lg:grid-cols-5 gap-3">
<SummaryCard
label="승률"
value={`${summaryQuery.data?.winRate ?? 0}%`}
sub={`${summaryQuery.data?.wins ?? 0}승 ${summaryQuery.data?.losses ?? 0}패`}
value={`${summary?.winRate ?? 0}%`}
sub={`${summary?.wins ?? 0}승 ${summary?.losses ?? 0}패`}
/>
<SummaryCard
label="KDA"
value={summaryQuery.data?.kda ?? 0}
sub={`${summaryQuery.data?.avgKills ?? 0} / ${summaryQuery.data?.avgDeaths ?? 0} / ${summaryQuery.data?.avgAssists ?? 0}`}
value={summary?.kda ?? 0}
sub={`${summary?.avgKills ?? 0} / ${summary?.avgDeaths ?? 0} / ${summary?.avgAssists ?? 0}`}
/>
<SummaryCard
label="최고 평점"
value={summaryQuery.data?.bestRating?.rating ?? "-"}
value={summary?.bestRating?.rating ?? "-"}
sub={
summaryQuery.data?.bestRating
? `${summaryQuery.data.bestRating.kills}/${summaryQuery.data.bestRating.deaths}/${summaryQuery.data.bestRating.assists}`
summary?.bestRating
? `${summary.bestRating.kills}/${summary.bestRating.deaths}/${summary.bestRating.assists}`
: "기록 없음"
}
/>
<SummaryCard
label="연승/연패"
value={
summaryQuery.data?.streak
? `${summaryQuery.data.streak.count}${summaryQuery.data.streak.type === "win" ? "연승" : "연패"}`
summary?.streak
? `${summary.streak.count}${summary.streak.type === "win" ? "연승" : "연패"}`
: "-"
}
sub="가장 최근 경기 기준"
@@ -817,7 +893,7 @@ export default function UserHistoryPage() {
자주 플레이한 챔피언
</div>
<div className="mt-3 flex items-center gap-3">
{(summaryQuery.data?.topChampions ?? []).map((champion) => (
{(summary?.topChampions ?? []).map((champion) => (
<button
type="button"
key={champion.championId}
@@ -835,7 +911,7 @@ export default function UserHistoryPage() {
</div>
</button>
))}
{(summaryQuery.data?.topChampions ?? []).length === 0 && (
{(summary?.topChampions ?? []).length === 0 && (
<span className="text-[11px] text-base-content/25">
기록 없음
</span>
@@ -890,14 +966,11 @@ export default function UserHistoryPage() {
<div className="flex items-center justify-between gap-3 mb-3">
<h2 className="text-sm font-bold text-base-content">매치 히스토리</h2>
<span className="text-[11px] text-base-content/35">
최근 저장:{" "}
{formatLastFetched(
recentMatchesQuery.data?.pages[0]?.lastFetchedAt,
)}
최근 저장: {formatLastFetched(historyLastFetchedAt)}
</span>
</div>
{recentMatchesQuery.isLoading ? (
{matchesLoading ? (
<div className="border border-base-content/10 bg-base-100 px-4 py-10 text-center text-sm text-base-content/35">
최근 경기를 불러오는 중...
</div>
@@ -917,16 +990,18 @@ export default function UserHistoryPage() {
</div>
)}
{recentMatchesQuery.hasNextPage && (
{hasNextPage && (
<button
type="button"
className="mt-3 w-full border border-base-content/15 bg-base-100 py-3 text-sm font-bold text-base-content/60 hover:border-primary/30 hover:text-primary disabled:opacity-40"
disabled={recentMatchesQuery.isFetchingNextPage}
onClick={() => recentMatchesQuery.fetchNextPage()}
disabled={isFetchingNextPage}
onClick={() =>
isInternalQueue
? internalHistoryQuery.fetchNextPage()
: recentMatchesQuery.fetchNextPage()
}
>
{recentMatchesQuery.isFetchingNextPage
? "불러오는 중..."
: "+ 더 보기"}
{isFetchingNextPage ? "불러오는 중..." : "+ 더 보기"}
</button>
)}
</section>