.
This commit is contained in:
1 parent
2250b6072e
commit
1bbfc901e8
17 files changed
+3471
-59
No files matched your search
@@ -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>
|
||||
|
||||
Reference in new issue
Block a user