.
This commit is contained in:
1 parent
60928bc165
commit
ca56af79e5
19 files changed
+3450
-21
No files matched your search
@@ -235,19 +235,24 @@ function TeamPanel({
|
||||
) : (
|
||||
team.members.map((member) => (
|
||||
<div key={`${member.userId}-${member.assignedPosition}`} className="px-3 py-1.5 flex items-center gap-2">
|
||||
<div className="w-6 h-6 bg-base-content/10 overflow-hidden shrink-0">
|
||||
<img
|
||||
src={profileIconUrl(ddragon, member.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<span className="text-[12px] font-medium text-base-content truncate block leading-tight">
|
||||
{member.summonerName}
|
||||
</span>
|
||||
</div>
|
||||
<Link
|
||||
to={`/users/${member.userId}/history`}
|
||||
className="flex flex-1 min-w-0 items-center gap-2 group"
|
||||
>
|
||||
<div className="w-6 h-6 bg-base-content/10 overflow-hidden shrink-0">
|
||||
<img
|
||||
src={profileIconUrl(ddragon, member.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<span className="text-[12px] font-medium text-base-content truncate block leading-tight group-hover:text-primary transition-colors">
|
||||
{member.summonerName}
|
||||
</span>
|
||||
</div>
|
||||
</Link>
|
||||
<PosBadge pos={member.assignedPosition} />
|
||||
<span className="text-[10px] text-amber-400/60 tabular-nums w-8 text-right">
|
||||
{member.cost}
|
||||
@@ -285,18 +290,24 @@ function PlayerSpotlight({
|
||||
<div className="border border-base-content/10 bg-base-100">
|
||||
<div className="p-5 border-b border-base-content/8">
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="w-16 h-16 bg-base-content/10 overflow-hidden shrink-0">
|
||||
<Link
|
||||
to={`/users/${player.userId}/history`}
|
||||
className="w-16 h-16 bg-base-content/10 overflow-hidden shrink-0"
|
||||
>
|
||||
<img
|
||||
src={profileIconUrl(ddragon, player.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
</Link>
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<h3 className="text-lg font-bold text-base-content leading-tight">
|
||||
<Link
|
||||
to={`/users/${player.userId}/history`}
|
||||
className="text-lg font-bold text-base-content leading-tight hover:text-primary transition-colors"
|
||||
>
|
||||
{player.summonerName}
|
||||
</h3>
|
||||
</Link>
|
||||
<span className="text-[10px] text-base-content/25">
|
||||
#{player.tag}
|
||||
</span>
|
||||
|
||||
@@ -100,7 +100,10 @@ function ParticipantRow({
|
||||
{index + 1}
|
||||
</td>
|
||||
<td className="py-2 px-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<Link
|
||||
to={`/users/${participant.userId}/history`}
|
||||
className="flex items-center gap-2 group"
|
||||
>
|
||||
<div className="w-7 h-7 bg-base-content/10 overflow-hidden shrink-0">
|
||||
<img
|
||||
src={profileIconUrl(ddragon, participant.profileIconId)}
|
||||
@@ -110,14 +113,14 @@ function ParticipantRow({
|
||||
/>
|
||||
</div>
|
||||
<div className="min-w-0">
|
||||
<span className="font-medium text-[13px] text-base-content truncate block leading-tight">
|
||||
<span className="font-medium text-[13px] text-base-content truncate block leading-tight group-hover:text-primary transition-colors">
|
||||
{participant.summonerName}
|
||||
</span>
|
||||
<span className="text-[10px] text-base-content/25 leading-tight">
|
||||
#{participant.tag}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</Link>
|
||||
</td>
|
||||
<td className="py-2 px-3">
|
||||
<TierCell participant={participant} />
|
||||
|
||||
@@ -0,0 +1,775 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { Link, useParams, useSearchParams } from 'react-router';
|
||||
import {
|
||||
useChampionStats,
|
||||
useDdragonManifest,
|
||||
useRecentMatches,
|
||||
useRecentSummary,
|
||||
useUserHistoryProfile,
|
||||
type UserHistoryFilters,
|
||||
} from '../api/hooks';
|
||||
import {
|
||||
formatTierLabel,
|
||||
getTierColorToken,
|
||||
} from '../api/mappers';
|
||||
import type {
|
||||
ApiChampionStatsRow,
|
||||
ApiRecentMatchView,
|
||||
DdragonManifest,
|
||||
RiotQueueGroup,
|
||||
RiotRankFilter,
|
||||
} from '../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../config';
|
||||
import {
|
||||
championDisplayName,
|
||||
championIconUrl,
|
||||
itemIconUrl,
|
||||
profileIconUrl,
|
||||
} from '../lib/ddragon';
|
||||
import {
|
||||
isRiotQueueGroup,
|
||||
isRiotRankFilter,
|
||||
LANE_LABELS,
|
||||
QUEUE_GROUP_TABS,
|
||||
RANK_FILTER_TABS,
|
||||
} from '../lib/riot-history';
|
||||
|
||||
type ChampionSortKey = 'games' | 'winRate' | 'kda' | 'avgCsPerMin';
|
||||
|
||||
const SORT_LABELS: Record<ChampionSortKey, string> = {
|
||||
games: '게임 수',
|
||||
winRate: '승률',
|
||||
kda: 'KDA',
|
||||
avgCsPerMin: '분당 CS',
|
||||
};
|
||||
|
||||
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 ratioClass(value: number) {
|
||||
if (value >= 55) return 'text-blue-400';
|
||||
if (value >= 50) return 'text-amber-400';
|
||||
return 'text-base-content/50';
|
||||
}
|
||||
|
||||
function kdaClass(value: number) {
|
||||
if (value >= 4) return 'text-amber-400';
|
||||
if (value >= 3) return 'text-emerald-400';
|
||||
return 'text-base-content/60';
|
||||
}
|
||||
|
||||
function FilterButton({
|
||||
active,
|
||||
children,
|
||||
onClick,
|
||||
}: {
|
||||
active: boolean;
|
||||
children: React.ReactNode;
|
||||
onClick: () => void;
|
||||
}) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClick}
|
||||
className={`px-3 py-2 text-[12px] font-semibold border-b-2 transition-colors ${
|
||||
active
|
||||
? 'border-primary text-primary bg-primary/5'
|
||||
: 'border-transparent text-base-content/45 hover:text-base-content'
|
||||
}`}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
function ChampionIcon({
|
||||
championId,
|
||||
manifest,
|
||||
size = 'md',
|
||||
}: {
|
||||
championId: number;
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
size?: 'sm' | 'md' | 'lg';
|
||||
}) {
|
||||
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' : 'w-8 h-8';
|
||||
|
||||
return (
|
||||
<div className={`${sizeClass} bg-base-content/10 overflow-hidden shrink-0`}>
|
||||
{iconUrl ? (
|
||||
<img
|
||||
src={iconUrl}
|
||||
alt={displayName}
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SummaryCard({
|
||||
label,
|
||||
value,
|
||||
sub,
|
||||
}: {
|
||||
label: string;
|
||||
value: React.ReactNode;
|
||||
sub?: React.ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="border border-base-content/8 bg-base-100 p-4">
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||||
{label}
|
||||
</div>
|
||||
<div className="mt-2 text-2xl font-black text-base-content tabular-nums">
|
||||
{value}
|
||||
</div>
|
||||
{sub && <div className="mt-1 text-[11px] text-base-content/40">{sub}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ChampionStatsTable({
|
||||
rows,
|
||||
manifest,
|
||||
selectedChampionId,
|
||||
onChampionSelect,
|
||||
}: {
|
||||
rows: ApiChampionStatsRow[];
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
selectedChampionId?: number;
|
||||
onChampionSelect: (championId: number | null) => void;
|
||||
}) {
|
||||
if (rows.length === 0) {
|
||||
return (
|
||||
<div className="border border-base-content/10 bg-base-100 px-4 py-10 text-center text-sm text-base-content/35">
|
||||
조건에 맞는 챔피언 통계가 아직 없습니다.
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
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-[860px]">
|
||||
<thead>
|
||||
<tr className="bg-base-200/50 border-b border-base-content/10 text-[11px] text-base-content/35 uppercase tracking-wider">
|
||||
<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">승/패</th>
|
||||
<th className="px-3 py-2.5 text-center">KDA</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">어시스트</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 text-center">필터</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((row) => {
|
||||
const displayName =
|
||||
championDisplayName(manifest, row.championId) ??
|
||||
String(row.championId);
|
||||
const selected = selectedChampionId === row.championId;
|
||||
return (
|
||||
<tr
|
||||
key={row.championId}
|
||||
className="border-b border-base-content/5 last:border-b-0 hover:bg-base-content/[0.02]"
|
||||
>
|
||||
<td className="px-3 py-2.5">
|
||||
<div className="flex items-center gap-2">
|
||||
<ChampionIcon championId={row.championId} manifest={manifest} />
|
||||
<span className="text-[13px] font-bold text-base-content">
|
||||
{displayName}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td className={`px-3 py-2.5 text-center text-[13px] font-bold ${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] tabular-nums text-base-content/55">
|
||||
<span className="text-blue-400">{row.wins}</span> /{' '}
|
||||
<span className="text-red-400">{row.losses}</span>
|
||||
</td>
|
||||
<td className={`px-3 py-2.5 text-center text-[13px] font-bold tabular-nums ${kdaClass(row.kda)}`}>
|
||||
{row.kda}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.totalKills}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.totalDeaths}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.totalAssists}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums text-base-content/55">
|
||||
{row.doubleKills}/{row.tripleKills}/{row.quadraKills}/{row.pentaKills}
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center text-[12px] tabular-nums">
|
||||
{row.avgCs} · {row.avgCsPerMin}/m
|
||||
</td>
|
||||
<td className="px-3 py-2.5 text-center">
|
||||
<button
|
||||
type="button"
|
||||
className={`text-[11px] px-2 py-1 border ${
|
||||
selected
|
||||
? 'border-primary/40 bg-primary/10 text-primary'
|
||||
: 'border-base-content/10 text-base-content/40 hover:text-base-content'
|
||||
}`}
|
||||
onClick={() => onChampionSelect(selected ? null : row.championId)}
|
||||
>
|
||||
{selected ? '해제' : '보기'}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ItemGrid({
|
||||
match,
|
||||
manifest,
|
||||
}: {
|
||||
match: ApiRecentMatchView;
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
}) {
|
||||
const slots = [...match.items, match.trinket];
|
||||
return (
|
||||
<div className="grid grid-cols-4 gap-1 w-[92px]">
|
||||
{slots.map((itemId, index) => {
|
||||
const url = itemIconUrl(manifest, itemId);
|
||||
return (
|
||||
<div
|
||||
key={`${match.matchId}-item-${index}`}
|
||||
className="w-5 h-5 bg-base-content/8 overflow-hidden border border-base-content/5"
|
||||
>
|
||||
{url ? (
|
||||
<img
|
||||
src={url}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
loading="lazy"
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function TeamMini({
|
||||
match,
|
||||
manifest,
|
||||
}: {
|
||||
match: ApiRecentMatchView;
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
}) {
|
||||
return (
|
||||
<div className="grid sm:grid-cols-2 gap-2 text-[11px]">
|
||||
{match.teams.map((team) => (
|
||||
<div
|
||||
key={`${match.matchId}-${team.side}`}
|
||||
className={`space-y-0.5 ${team.win ? 'text-base-content/70' : 'text-base-content/35'}`}
|
||||
>
|
||||
{team.participants.map((participant) => {
|
||||
const championName =
|
||||
championDisplayName(manifest, participant.championId) ??
|
||||
String(participant.championId);
|
||||
return (
|
||||
<div
|
||||
key={`${participant.puuid}-${participant.championId}`}
|
||||
className="flex items-center gap-1 min-w-0"
|
||||
>
|
||||
<ChampionIcon
|
||||
championId={participant.championId}
|
||||
manifest={manifest}
|
||||
size="sm"
|
||||
/>
|
||||
<span className="truncate">
|
||||
{participant.gameName || championName}
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function RecentMatchCard({
|
||||
match,
|
||||
manifest,
|
||||
}: {
|
||||
match: ApiRecentMatchView;
|
||||
manifest: DdragonManifest | null | undefined;
|
||||
}) {
|
||||
const championName =
|
||||
championDisplayName(manifest, match.championId) ?? String(match.championId);
|
||||
const accent = match.win ? 'border-l-blue-500' : 'border-l-red-500';
|
||||
const resultClass = match.win ? 'text-blue-400' : 'text-red-400';
|
||||
|
||||
return (
|
||||
<article className={`border border-l-4 ${accent} border-base-content/10 bg-base-100`}>
|
||||
<div className="p-4 grid lg:grid-cols-[120px_1fr_120px_1.5fr_32px] gap-4 items-center">
|
||||
<div className="text-center lg:text-left">
|
||||
<div className={`text-[12px] font-black ${resultClass}`}>
|
||||
{match.remake ? '다시하기' : match.win ? '승리' : '패배'}
|
||||
</div>
|
||||
<div className="text-[11px] text-base-content/35 mt-1">
|
||||
{match.queueLabel}
|
||||
</div>
|
||||
<div className="text-[11px] text-base-content/25">
|
||||
{formatDate(match.gameCreation)}
|
||||
</div>
|
||||
<div className="text-[11px] text-base-content/25">
|
||||
{formatDuration(match.gameDuration)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3 min-w-0">
|
||||
<ChampionIcon championId={match.championId} manifest={manifest} size="lg" />
|
||||
<div className="min-w-0">
|
||||
<div className="font-bold text-base-content truncate">
|
||||
{championName}
|
||||
</div>
|
||||
<div className="text-[11px] text-base-content/35">
|
||||
Lv.{match.championLevel} ·{' '}
|
||||
{(LANE_LABELS[match.teamPosition] ?? match.teamPosition) || '포지션 없음'}
|
||||
</div>
|
||||
<div className="mt-1 text-[10px] text-base-content/30">
|
||||
스펠 {match.summonerSpells.join(' / ')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="text-center">
|
||||
<div className="text-lg font-black tabular-nums">
|
||||
<span>{match.kills}</span>
|
||||
<span className="text-base-content/25"> / </span>
|
||||
<span className="text-red-400">{match.deaths}</span>
|
||||
<span className="text-base-content/25"> / </span>
|
||||
<span>{match.assists}</span>
|
||||
</div>
|
||||
<div className={`text-[12px] font-bold tabular-nums ${kdaClass(match.kda)}`}>
|
||||
{match.deaths === 0 ? 'Perfect' : `${match.kda} 평점`}
|
||||
</div>
|
||||
<div className="mt-1 text-[11px] text-base-content/35">
|
||||
킬 관여 {match.killParticipation}%
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid sm:grid-cols-[100px_1fr] gap-4 items-center">
|
||||
<div className="space-y-1 text-[11px] text-base-content/45">
|
||||
<div>
|
||||
CS <span className="font-bold text-base-content/70">{match.totalCs}</span>{' '}
|
||||
({match.csPerMin}/m)
|
||||
</div>
|
||||
<div>
|
||||
시야 <span className="font-bold text-base-content/70">{match.visionScore}</span>{' '}
|
||||
제어와드 {match.controlWardsBought}
|
||||
</div>
|
||||
<div>
|
||||
피해량{' '}
|
||||
<span className="font-bold text-base-content/70">
|
||||
{match.damageDealtToChampions.toLocaleString()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-start gap-3">
|
||||
<ItemGrid match={match} manifest={manifest} />
|
||||
<TeamMini match={match} manifest={manifest} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="hidden lg:flex justify-end">
|
||||
<div className={`w-2 h-14 ${match.win ? 'bg-blue-500/70' : 'bg-red-500/70'}`} />
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
);
|
||||
}
|
||||
|
||||
export default function UserHistoryPage() {
|
||||
const { userId } = useParams();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [championSearch, setChampionSearch] = useState('');
|
||||
const [sortKey, setSortKey] = useState<ChampionSortKey>('games');
|
||||
const queueGroupParam = searchParams.get('queueGroup');
|
||||
const rankParam = searchParams.get('rank');
|
||||
const queueGroup: RiotQueueGroup = isRiotQueueGroup(queueGroupParam)
|
||||
? queueGroupParam
|
||||
: 'summoners-rift';
|
||||
const rank: RiotRankFilter = 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 championStatsQuery = useChampionStats(
|
||||
userId,
|
||||
aggregateFilters,
|
||||
DEFAULT_COMMUNITY_ID,
|
||||
);
|
||||
const summaryQuery = useRecentSummary(userId, filters, DEFAULT_COMMUNITY_ID);
|
||||
const recentMatchesQuery = useRecentMatches(userId, filters, DEFAULT_COMMUNITY_ID);
|
||||
|
||||
const profile = profileQuery.data;
|
||||
const primaryTier =
|
||||
profile?.tiers.find((tier) => tier.queueType === 'RANKED_SOLO_5x5') ??
|
||||
profile?.tiers[0];
|
||||
const matches =
|
||||
recentMatchesQuery.data?.pages.flatMap((page) => page.matches) ?? [];
|
||||
const selectedChampionName = championId
|
||||
? championDisplayName(ddragon, championId) ?? String(championId)
|
||||
: null;
|
||||
|
||||
const visibleChampionRows = useMemo(() => {
|
||||
const rows = 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]);
|
||||
}, [championSearch, championStatsQuery.data?.champions, ddragon, sortKey]);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (!DEFAULT_COMMUNITY_ID) {
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 py-20 text-center">
|
||||
<span className="text-sm text-amber-600">
|
||||
`VITE_DEFAULT_COMMUNITY_ID` 설정이 필요합니다.
|
||||
</span>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (profileQuery.isLoading) {
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 py-20 text-center">
|
||||
<span className="text-sm text-base-content/40">
|
||||
소환사 전적을 불러오는 중...
|
||||
</span>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
if (profileQuery.error || !profile) {
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 py-20 text-center">
|
||||
<h2 className="text-lg font-bold mb-2">소환사를 찾을 수 없습니다</h2>
|
||||
<Link to="/" 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="/"
|
||||
className="inline-flex items-center gap-1 text-xs text-base-content/40 hover:text-base-content transition-colors mb-5"
|
||||
>
|
||||
← 목록으로
|
||||
</Link>
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 p-5 mb-5">
|
||||
<div className="flex flex-col sm:flex-row sm:items-center gap-4">
|
||||
<div className="w-16 h-16 bg-base-content/10 overflow-hidden shrink-0">
|
||||
<img
|
||||
src={profileIconUrl(ddragon, profile.profileIconId)}
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<h1 className="text-2xl font-black text-base-content">
|
||||
{profile.gameName}
|
||||
</h1>
|
||||
<span className="text-sm text-base-content/35">
|
||||
#{profile.tagLine}
|
||||
</span>
|
||||
</div>
|
||||
<div className="mt-2 flex flex-wrap items-center gap-3 text-xs text-base-content/40">
|
||||
<span>Lv.{profile.summonerLevel}</span>
|
||||
{primaryTier ? (
|
||||
<span className={`font-bold ${getTierColorToken(primaryTier)}`}>
|
||||
{formatTierLabel(primaryTier)} {primaryTier.leaguePoints}LP
|
||||
</span>
|
||||
) : (
|
||||
<span>랭크 정보 없음</span>
|
||||
)}
|
||||
<span>시즌: {profile.season.label}</span>
|
||||
<span>최근 저장: {formatLastFetched(profile.lastFetchedAt)}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="border border-dashed border-base-content/10 px-3 py-2 text-[11px] text-base-content/35 sm:text-right">
|
||||
이 페이지는 저장된 경기 DB만 조회합니다.
|
||||
<br />
|
||||
화면 진입 시 Riot Match API 호출은 없습니다.
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 mb-5">
|
||||
<div className="flex flex-wrap border-b border-base-content/8">
|
||||
{QUEUE_GROUP_TABS.map((tab) => (
|
||||
<FilterButton
|
||||
key={tab.value}
|
||||
active={queueGroup === tab.value}
|
||||
onClick={() => updateSearch({ queueGroup: tab.value, championId: null })}
|
||||
>
|
||||
{tab.label}
|
||||
</FilterButton>
|
||||
))}
|
||||
</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>
|
||||
{selectedChampionName && (
|
||||
<button
|
||||
type="button"
|
||||
className="text-[11px] px-2.5 py-1 border border-primary/30 text-primary bg-primary/5"
|
||||
onClick={() => updateSearch({ championId: null })}
|
||||
>
|
||||
{selectedChampionName} 필터 해제
|
||||
</button>
|
||||
)}
|
||||
{profile.seasons.length > 0 && (
|
||||
<select
|
||||
value={filters.seasonId ?? profile.season.id}
|
||||
onChange={(event) =>
|
||||
updateSearch({ seasonId: event.target.value, championId: null })
|
||||
}
|
||||
className="border border-base-content/10 bg-transparent px-3 py-2 text-xs"
|
||||
>
|
||||
{profile.seasons.map((season) => (
|
||||
<option key={season.id} value={season.id}>
|
||||
{season.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="mb-6">
|
||||
<h2 className="text-sm font-bold text-base-content mb-3">
|
||||
최근 {summaryQuery.data?.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}패`}
|
||||
/>
|
||||
<SummaryCard
|
||||
label="KDA"
|
||||
value={summaryQuery.data?.kda ?? 0}
|
||||
sub={`${summaryQuery.data?.avgKills ?? 0} / ${summaryQuery.data?.avgDeaths ?? 0} / ${summaryQuery.data?.avgAssists ?? 0}`}
|
||||
/>
|
||||
<SummaryCard
|
||||
label="최고 평점"
|
||||
value={summaryQuery.data?.bestRating?.rating ?? '-'}
|
||||
sub={
|
||||
summaryQuery.data?.bestRating
|
||||
? `${summaryQuery.data.bestRating.kills}/${summaryQuery.data.bestRating.deaths}/${summaryQuery.data.bestRating.assists}`
|
||||
: '기록 없음'
|
||||
}
|
||||
/>
|
||||
<SummaryCard
|
||||
label="연승/연패"
|
||||
value={
|
||||
summaryQuery.data?.streak
|
||||
? `${summaryQuery.data.streak.count}${summaryQuery.data.streak.type === 'win' ? '연승' : '연패'}`
|
||||
: '-'
|
||||
}
|
||||
sub="가장 최근 경기 기준"
|
||||
/>
|
||||
<div className="border border-base-content/8 bg-base-100 p-4">
|
||||
<div className="text-[10px] font-bold uppercase tracking-wider text-base-content/30">
|
||||
자주 플레이한 챔피언
|
||||
</div>
|
||||
<div className="mt-3 flex items-center gap-3">
|
||||
{(summaryQuery.data?.topChampions ?? []).map((champion) => (
|
||||
<button
|
||||
type="button"
|
||||
key={champion.championId}
|
||||
className="text-center group"
|
||||
onClick={() => updateSearch({ championId: champion.championId })}
|
||||
>
|
||||
<ChampionIcon
|
||||
championId={champion.championId}
|
||||
manifest={ddragon}
|
||||
/>
|
||||
<div className="mt-1 text-[10px] text-base-content/40 group-hover:text-primary">
|
||||
{champion.winRate}%
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
{(summaryQuery.data?.topChampions ?? []).length === 0 && (
|
||||
<span className="text-[11px] text-base-content/25">기록 없음</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="mb-6">
|
||||
<div className="flex flex-col sm:flex-row sm:items-end sm:justify-between gap-3 mb-3">
|
||||
<div>
|
||||
<h2 className="text-sm font-bold text-base-content">
|
||||
챔피언 통계
|
||||
</h2>
|
||||
<p className="mt-1 text-[11px] text-base-content/35">
|
||||
저장된 매치 기준으로 집계합니다. Riot API 갱신은 별도 큐 작업으로 분리 예정입니다.
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<input
|
||||
value={championSearch}
|
||||
onChange={(event) => setChampionSearch(event.target.value)}
|
||||
placeholder="챔피언 검색"
|
||||
className="border border-base-content/10 bg-transparent px-3 py-2 text-xs focus:outline-none focus:border-primary/30"
|
||||
/>
|
||||
<select
|
||||
value={sortKey}
|
||||
onChange={(event) => setSortKey(event.target.value as ChampionSortKey)}
|
||||
className="border border-base-content/10 bg-transparent px-3 py-2 text-xs"
|
||||
>
|
||||
{(Object.keys(SORT_LABELS) as ChampionSortKey[]).map((key) => (
|
||||
<option key={key} value={key}>
|
||||
{SORT_LABELS[key]}순
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<ChampionStatsTable
|
||||
rows={visibleChampionRows}
|
||||
manifest={ddragon}
|
||||
selectedChampionId={championId}
|
||||
onChampionSelect={(nextChampionId) =>
|
||||
updateSearch({ championId: nextChampionId })
|
||||
}
|
||||
/>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<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)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{recentMatchesQuery.isLoading ? (
|
||||
<div className="border border-base-content/10 bg-base-100 px-4 py-10 text-center text-sm text-base-content/35">
|
||||
최근 경기를 불러오는 중...
|
||||
</div>
|
||||
) : matches.length === 0 ? (
|
||||
<div className="border border-base-content/10 bg-base-100 px-4 py-10 text-center text-sm text-base-content/35">
|
||||
조건에 맞는 최근 경기 기록이 없습니다.
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
{matches.map((match) => (
|
||||
<RecentMatchCard
|
||||
key={match.matchId}
|
||||
match={match}
|
||||
manifest={ddragon}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{recentMatchesQuery.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()}
|
||||
>
|
||||
{recentMatchesQuery.isFetchingNextPage ? '불러오는 중...' : '+ 더 보기'}
|
||||
</button>
|
||||
)}
|
||||
</section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user