diff --git a/apps/web/src/pages/CommunityInternalStatsPage.tsx b/apps/web/src/pages/CommunityInternalStatsPage.tsx new file mode 100644 index 00000000..667fb046 --- /dev/null +++ b/apps/web/src/pages/CommunityInternalStatsPage.tsx @@ -0,0 +1,406 @@ +import { Link, useLocation, 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'; +import { sideShortLabel, teamIndexColorClasses, teamIndexLabel } from '../lib/league'; + +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 sideShortLabel(side); +} + +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['data']; +}) { + const icon = championIconUrl(manifest, championId); + const name = championDisplayName(manifest, championId) ?? String(championId); + return ( + + + {icon ? : null} + + {name} + + ); +} + +function MatchCard({ + match, + manifest, +}: { + match: ApiInternalMatchCard; + manifest: ReturnType['data']; +}) { + const primarySeries = match.seriesResults[0]; + const teamName = (teamIndex: number) => + teamIndexLabel( + teamIndex, + match.teams.find((team) => team.teamIndex === teamIndex)?.name, + ); + + return ( + +
+
+
+
+ {formatDateTime(match.scheduledAt)} +
+

+ {match.title} +

+
+ {match.games.map((game) => ( + + {game.gameNumber}경기 + {game.winnerSide && game.winnerTeamIndex ? ( + + {teamName(game.winnerTeamIndex)} 승 ({sideLabel(game.winnerSide)}) + + ) : ( + '대기' + )} + {formatDuration(game.gameDuration)} + + ))} +
+
+ +
+ {primarySeries && ( +
+
+
{primarySeries.teamAWins}
+
+ {teamName(primarySeries.teamAIndex)} +
+
+
VS
+
+
{primarySeries.teamBWins}
+
+ {teamName(primarySeries.teamBIndex)} +
+
+
+ )} +
+ +
+ {match.teams.map((team) => ( +
+
+ {team.name} +
+
+ {team.members.slice(0, 5).map((member) => ( +
+ + + + + {member.summonerName} + +
+ ))} +
+
+ ))} +
+
+
+ + ); +} + +function HighlightCard({ + title, + highlight, + suffix = '', +}: { + title: string; + highlight: ApiLeaderHighlight | null | undefined; + suffix?: string; +}) { + return ( +
+
+ {title} +
+
+ {highlight ? `${highlight.metric}${suffix}` : '-'} +
+
+ {highlight?.summonerName ?? '기록 없음'} +
+
+ ); +} + +function LeaderboardTable({ + rows, + manifest, +}: { + rows: ApiLeaderboardRow[]; + manifest: ReturnType['data']; +}) { + const location = useLocation(); + const historyBackTo = `${location.pathname}${location.search}${location.hash}`; + + return ( +
+
+ + + + + + + + + + + + + + + + {rows.map((row, index) => ( + + + + + + + + + + + + ))} + {rows.length === 0 && ( + + + + )} + +
#소환사승률게임KDAGPM킬관여분당 CS주 챔피언
+ {index + 1} + + + + + + + {row.summonerName} + + + + {row.winRate}% + + {row.games} + + {row.kda} + + {row.avgGoldPerMin} + + {row.avgKillParticipation}% + + {row.avgCsPerMin} + +
+ {row.topChampions.map((champion) => ( + + ))} +
+
+ 아직 집계할 내전 기록이 없습니다. +
+
+
+ ); +} + +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 ( +
+ `VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다. +
+ ); + } + + return ( +
+ + ← 홈으로 + + +
+
+
+

+ Community Records +

+

+ {communityQuery.data?.name ?? '커뮤니티'} 내전 전적 +

+

+ 토너먼트 코드로 수집된 결과를 기준으로 매치, 선수 순위, 팀 인사이트를 보여줍니다. +

+
+
+
+ 시즌 +
+
{season?.label ?? '현재 시즌'}
+
+
+
+ +
+ + + + + +
+ +
+
+

최근 내전

+
+ 블루 승률 {insightsQuery.data?.sideWinRate.blue ?? 0}% · 레드 승률{' '} + {insightsQuery.data?.sideWinRate.red ?? 0}% +
+
+ {matchesQuery.isLoading ? ( +
+ 내전 기록을 불러오는 중... +
+ ) : ( +
+ {matches.map((match) => ( + + ))} + {matches.length === 0 && ( +
+ 아직 수집된 내전 결과가 없습니다. +
+ )} +
+ )} + {matchesQuery.hasNextPage && ( + + )} +
+ +
+
+

선수 순위

+
+ 포지션은 Riot Match의 라인 정보를 기준으로 합니다. +
+
+ +
+
+ ); +} diff --git a/apps/web/src/pages/InternalMatchDetailPage.tsx b/apps/web/src/pages/InternalMatchDetailPage.tsx new file mode 100644 index 00000000..7797796b --- /dev/null +++ b/apps/web/src/pages/InternalMatchDetailPage.tsx @@ -0,0 +1,281 @@ +import { Link, useLocation, 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 { sideShortLabel, teamIndexColorClasses, teamIndexLabel } from '../lib/league'; +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 sideShortLabel(side); +} + +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['data']; +}) { + const icon = championIconUrl(manifest, championId); + const name = championDisplayName(manifest, championId) ?? String(championId); + return ( +
+ + {icon ? : null} + + {name} +
+ ); +} + +function ItemStrip({ + items, + trinket, + manifest, +}: { + items: number[]; + trinket: number; + manifest: ReturnType['data']; +}) { + return ( +
+ {[...items, trinket].map((itemId, index) => { + const icon = itemIconUrl(manifest, itemId); + return ( + + {icon ? : null} + + ); + })} +
+ ); +} + +function GamePanel({ + game, + manifest, +}: { + game: ApiInternalMatchDetailResponse['games'][number]; + manifest: ReturnType['data']; +}) { + const location = useLocation(); + const historyBackTo = `${location.pathname}${location.search}${location.hash}`; + + return ( +
+
+
+

+ {game.gameNumber}경기 +

+

+ {formatDateTime(game.gameCreation)} · {formatDuration(game.gameDuration)} ·{' '} + {game.riotMatchId} +

+
+
+ {game.teams.map((team) => ( + + {teamIndexLabel(team.teamIndex)} ({sideLabel(team.side)}){' '} + {team.win ? '승' : '패'} + + ))} +
+
+ + {game.teams.map((team) => ( +
+
+ {teamIndexLabel(team.teamIndex)} ({sideLabel(team.side)}) · 바론 {team.objectives.baron} · 드래곤{' '} + {team.objectives.dragon} · 타워 {team.objectives.tower} +
+
+ + + + + + + + + + + + + + + + {team.participants.map((participant) => ( + + + + + + + + + + + + ))} + +
소환사챔피언포지션K/D/ACSGPM킬관여피해비중아이템
+ {participant.userId ? ( + + {participant.summonerName} + + ) : ( + + {participant.summonerName} + + )} + + + + {LANE_LABELS[participant.teamPosition] ?? participant.teamPosition ?? '-'} + + {participant.kills} + / + {participant.deaths} + / + {participant.assists} + + {participant.cs} ({participant.csPerMin}/m) + + {participant.gpm} + + {participant.killParticipation}% + + {participant.damageShare}% + + +
+
+
+ ))} +
+ ); +} + +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 ( +
+ 내전 상세 기록을 불러오는 중... +
+ ); + } + + if (detailQuery.error || !detail) { + return ( +
+

내전 기록을 찾을 수 없습니다

+ + 내전 전적으로 돌아가기 + +
+ ); + } + + const primarySeries = detail.match.seriesResults[0]; + const teamName = (teamIndex: number) => + teamIndexLabel( + teamIndex, + detail.match.teams.find((team) => team.teamIndex === teamIndex)?.name, + ); + + return ( +
+ + ← 내전 전적 + + +
+
+
+

+ {detail.match.title} +

+

+ {formatDateTime(detail.match.scheduledAt)} · {detail.match.gameCount}전제 +

+
+ {primarySeries && ( +
+
+
{primarySeries.teamAWins}
+
+ {teamName(primarySeries.teamAIndex)} +
+
+
VS
+
+
{primarySeries.teamBWins}
+
+ {teamName(primarySeries.teamBIndex)} +
+
+
+ )} +
+
+ +
+ {detail.games.map((game) => ( + + ))} +
+
+ ); +}