.
This commit is contained in:
1 parent
ca56af79e5
commit
8b8dec4c44
14 files changed
+1155
-7
No files matched your search
@@ -1,25 +1,31 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { Link, useParams, useSearchParams } from 'react-router';
|
||||
import {
|
||||
useChampionStats,
|
||||
useDdragonManifest,
|
||||
useRecentMatches,
|
||||
useRecentSummary,
|
||||
useRefreshUserHistory,
|
||||
useUserHistoryProfile,
|
||||
type UserHistoryFilters,
|
||||
} from '../api/hooks';
|
||||
import { useRiotRefreshSocket } from '../api/useRiotRefreshSocket';
|
||||
import {
|
||||
formatTierLabel,
|
||||
getTierColorToken,
|
||||
} from '../api/mappers';
|
||||
import type {
|
||||
ApiChampionStatsRow,
|
||||
ApiEnqueueRefreshResult,
|
||||
ApiRiotRefreshEvent,
|
||||
ApiRecentMatchView,
|
||||
DdragonManifest,
|
||||
RiotQueueGroup,
|
||||
RiotRankFilter,
|
||||
} from '../api/types';
|
||||
import { DEFAULT_COMMUNITY_ID } from '../config';
|
||||
import { ApiError } from '../lib/api';
|
||||
import {
|
||||
championDisplayName,
|
||||
championIconUrl,
|
||||
@@ -68,6 +74,27 @@ function formatLastFetched(value: string | null | undefined) {
|
||||
}).format(new Date(value));
|
||||
}
|
||||
|
||||
function formatEta(seconds: number) {
|
||||
if (seconds < 60) return `${Math.max(1, Math.ceil(seconds))}초`;
|
||||
return `${Math.ceil(seconds / 60)}분`;
|
||||
}
|
||||
|
||||
function formatRefreshError(error: unknown) {
|
||||
if (error instanceof ApiError) {
|
||||
const data = error.data;
|
||||
if (
|
||||
typeof data === 'object' &&
|
||||
data !== null &&
|
||||
'retryAfterSeconds' in data &&
|
||||
typeof data.retryAfterSeconds === 'number'
|
||||
) {
|
||||
return `잠시 후 다시 시도해 주세요. 약 ${formatEta(data.retryAfterSeconds)} 뒤에 요청할 수 있습니다.`;
|
||||
}
|
||||
return error.message;
|
||||
}
|
||||
return error instanceof Error ? error.message : '갱신 요청에 실패했습니다.';
|
||||
}
|
||||
|
||||
function ratioClass(value: number) {
|
||||
if (value >= 55) return 'text-blue-400';
|
||||
if (value >= 50) return 'text-amber-400';
|
||||
@@ -428,9 +455,13 @@ function RecentMatchCard({
|
||||
|
||||
export default function UserHistoryPage() {
|
||||
const { userId } = useParams();
|
||||
const queryClient = useQueryClient();
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
const [championSearch, setChampionSearch] = useState('');
|
||||
const [sortKey, setSortKey] = useState<ChampionSortKey>('games');
|
||||
const [refreshResult, setRefreshResult] =
|
||||
useState<ApiEnqueueRefreshResult | null>(null);
|
||||
const [refreshNotice, setRefreshNotice] = useState<string | null>(null);
|
||||
const queueGroupParam = searchParams.get('queueGroup');
|
||||
const rankParam = searchParams.get('rank');
|
||||
const queueGroup: RiotQueueGroup = isRiotQueueGroup(queueGroupParam)
|
||||
@@ -461,6 +492,7 @@ export default function UserHistoryPage() {
|
||||
);
|
||||
const summaryQuery = useRecentSummary(userId, filters, DEFAULT_COMMUNITY_ID);
|
||||
const recentMatchesQuery = useRecentMatches(userId, filters, DEFAULT_COMMUNITY_ID);
|
||||
const refreshMutation = useRefreshUserHistory(userId, DEFAULT_COMMUNITY_ID);
|
||||
|
||||
const profile = profileQuery.data;
|
||||
const primaryTier =
|
||||
@@ -485,6 +517,25 @@ export default function UserHistoryPage() {
|
||||
.sort((left, right) => right[sortKey] - left[sortKey]);
|
||||
}, [championSearch, championStatsQuery.data?.champions, ddragon, sortKey]);
|
||||
|
||||
const refreshSocket = useRiotRefreshSocket({
|
||||
puuid: profile?.puuid,
|
||||
parentJobId: refreshResult?.parentJobId,
|
||||
onEvent: (event: ApiRiotRefreshEvent) => {
|
||||
if (!profile || event.puuid !== profile.puuid) return;
|
||||
void invalidateHistoryQueries();
|
||||
if (event.state === 'completed') {
|
||||
setRefreshNotice('갱신이 완료되어 전적을 다시 불러왔습니다.');
|
||||
}
|
||||
if (event.state === 'failed') {
|
||||
setRefreshNotice(
|
||||
event.error
|
||||
? `갱신 실패: ${event.error}`
|
||||
: '갱신에 실패했습니다. 잠시 후 다시 시도해 주세요.',
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
function updateSearch(next: Partial<Record<string, string | number | null>>) {
|
||||
const params = new URLSearchParams(searchParams);
|
||||
for (const [key, value] of Object.entries(next)) {
|
||||
@@ -497,6 +548,44 @@ export default function UserHistoryPage() {
|
||||
setSearchParams(params);
|
||||
}
|
||||
|
||||
async function invalidateHistoryQueries() {
|
||||
await Promise.all([
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['user-history-profile', DEFAULT_COMMUNITY_ID, userId ?? null],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['user-champion-stats', DEFAULT_COMMUNITY_ID, userId ?? null],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['user-recent-summary', DEFAULT_COMMUNITY_ID, userId ?? null],
|
||||
}),
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: ['user-recent-matches', DEFAULT_COMMUNITY_ID, userId ?? null],
|
||||
}),
|
||||
]);
|
||||
}
|
||||
|
||||
function handleRefresh() {
|
||||
if (!userId) return;
|
||||
refreshMutation.mutate(
|
||||
{ queueGroups: [queueGroup], priority: 'high' },
|
||||
{
|
||||
onSuccess: (result) => {
|
||||
setRefreshResult(result);
|
||||
const alreadyQueued = result.subJobs.every((job) => job.alreadyQueued);
|
||||
setRefreshNotice(
|
||||
alreadyQueued
|
||||
? `이미 갱신 작업이 대기 중입니다. 예상 ${formatEta(result.totalEtaSeconds)} 후 반영됩니다.`
|
||||
: `갱신을 요청했습니다. 예상 ${formatEta(result.totalEtaSeconds)} 후 반영됩니다.`,
|
||||
);
|
||||
},
|
||||
onError: (error) => {
|
||||
setRefreshNotice(formatRefreshError(error));
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (!DEFAULT_COMMUNITY_ID) {
|
||||
return (
|
||||
<main className="max-w-6xl mx-auto px-4 py-20 text-center">
|
||||
@@ -568,12 +657,30 @@ export default function UserHistoryPage() {
|
||||
<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 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 갱신은 버튼 클릭 시 큐에서 처리합니다.
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary btn-xs px-3"
|
||||
disabled={refreshMutation.isPending || !userId}
|
||||
onClick={handleRefresh}
|
||||
>
|
||||
{refreshMutation.isPending ? '요청 중...' : '현재 탭 갱신'}
|
||||
</button>
|
||||
<div className="text-[10px] text-base-content/25">
|
||||
갱신 소켓: {refreshSocket.connectionStatus}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{(refreshNotice || refreshSocket.error) && (
|
||||
<div className="mt-4 border border-primary/15 bg-primary/5 px-3 py-2 text-xs text-base-content/55">
|
||||
{refreshNotice ?? refreshSocket.error}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="border border-base-content/10 bg-base-100 mb-5">
|
||||
|
||||
Reference in new issue
Block a user