.
This commit is contained in:
1 parent
60928bc165
commit
ca56af79e5
19 files changed
+3450
-21
No files matched your search
+124
-1
@@ -1,6 +1,6 @@
|
||||
import { InteractionStatus } from '@azure/msal-browser';
|
||||
import { useMsal } from '@azure/msal-react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useInfiniteQuery, useQuery } from '@tanstack/react-query';
|
||||
import { DEFAULT_COMMUNITY_ID, useAuthUserId } from '../config';
|
||||
import { apiFetch } from '../lib/api';
|
||||
import {
|
||||
@@ -9,12 +9,18 @@ import {
|
||||
} from '../lib/auth/msal.config';
|
||||
import type {
|
||||
ApiAuction,
|
||||
ApiChampionStatsResponse,
|
||||
ApiCommunity,
|
||||
ApiMatch,
|
||||
ApiRecentMatchesResponse,
|
||||
ApiRecentSummaryResponse,
|
||||
ApiUserHistoryProfile,
|
||||
DdragonManifest,
|
||||
MatchStatus,
|
||||
MatchesResponse,
|
||||
MeResponse,
|
||||
RiotQueueGroup,
|
||||
RiotRankFilter,
|
||||
} from './types';
|
||||
|
||||
const DDRAGON_MANIFEST_STALE_MS = 24 * 60 * 60 * 1000;
|
||||
@@ -24,6 +30,13 @@ interface MatchesQueryOptions {
|
||||
limit?: number;
|
||||
}
|
||||
|
||||
export interface UserHistoryFilters {
|
||||
queueGroup?: RiotQueueGroup;
|
||||
rank?: RiotRankFilter;
|
||||
seasonId?: string;
|
||||
championId?: number;
|
||||
}
|
||||
|
||||
function createMatchesPath(
|
||||
communityId: string,
|
||||
options: MatchesQueryOptions = {},
|
||||
@@ -83,6 +96,116 @@ export function useAuction(
|
||||
});
|
||||
}
|
||||
|
||||
function createUserHistoryPath(
|
||||
communityId: string,
|
||||
userId: string,
|
||||
resource: string,
|
||||
filters: UserHistoryFilters = {},
|
||||
extra: Record<string, string | number | null | undefined> = {},
|
||||
) {
|
||||
const searchParams = new URLSearchParams();
|
||||
if (filters.queueGroup) searchParams.set('queueGroup', filters.queueGroup);
|
||||
if (filters.rank) searchParams.set('rank', filters.rank);
|
||||
if (filters.seasonId) searchParams.set('seasonId', filters.seasonId);
|
||||
if (filters.championId) searchParams.set('championId', String(filters.championId));
|
||||
for (const [key, value] of Object.entries(extra)) {
|
||||
if (value !== null && value !== undefined && value !== '') {
|
||||
searchParams.set(key, String(value));
|
||||
}
|
||||
}
|
||||
|
||||
const queryString = searchParams.toString();
|
||||
return `/communities/${communityId}/users/${userId}/${resource}${queryString ? `?${queryString}` : ''}`;
|
||||
}
|
||||
|
||||
export function useUserHistoryProfile(
|
||||
userId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['user-history-profile', communityId, userId ?? null],
|
||||
queryFn: () =>
|
||||
apiFetch<ApiUserHistoryProfile>(
|
||||
`/communities/${communityId}/users/${userId}/history-profile`,
|
||||
),
|
||||
enabled: Boolean(communityId && userId),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useChampionStats(
|
||||
userId: string | undefined,
|
||||
filters: UserHistoryFilters,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'user-champion-stats',
|
||||
communityId,
|
||||
userId ?? null,
|
||||
filters.queueGroup ?? null,
|
||||
filters.rank ?? null,
|
||||
filters.seasonId ?? null,
|
||||
],
|
||||
queryFn: () =>
|
||||
apiFetch<ApiChampionStatsResponse>(
|
||||
createUserHistoryPath(communityId, userId ?? '', 'champion-stats', filters),
|
||||
),
|
||||
enabled: Boolean(communityId && userId),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRecentSummary(
|
||||
userId: string | undefined,
|
||||
filters: UserHistoryFilters,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: [
|
||||
'user-recent-summary',
|
||||
communityId,
|
||||
userId ?? null,
|
||||
filters.queueGroup ?? null,
|
||||
filters.rank ?? null,
|
||||
filters.seasonId ?? null,
|
||||
filters.championId ?? null,
|
||||
],
|
||||
queryFn: () =>
|
||||
apiFetch<ApiRecentSummaryResponse>(
|
||||
createUserHistoryPath(communityId, userId ?? '', 'recent-summary', filters),
|
||||
),
|
||||
enabled: Boolean(communityId && userId),
|
||||
});
|
||||
}
|
||||
|
||||
export function useRecentMatches(
|
||||
userId: string | undefined,
|
||||
filters: UserHistoryFilters,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useInfiniteQuery({
|
||||
queryKey: [
|
||||
'user-recent-matches',
|
||||
communityId,
|
||||
userId ?? null,
|
||||
filters.queueGroup ?? null,
|
||||
filters.rank ?? null,
|
||||
filters.seasonId ?? null,
|
||||
filters.championId ?? null,
|
||||
],
|
||||
queryFn: ({ pageParam }) =>
|
||||
apiFetch<ApiRecentMatchesResponse>(
|
||||
createUserHistoryPath(communityId, userId ?? '', 'recent-matches', filters, {
|
||||
cursor: pageParam,
|
||||
limit: 10,
|
||||
}),
|
||||
),
|
||||
initialPageParam: null as number | null,
|
||||
getNextPageParam: (lastPage) => lastPage.nextCursor,
|
||||
enabled: Boolean(communityId && userId),
|
||||
});
|
||||
}
|
||||
|
||||
export function useDdragonManifest(locale = 'ko_KR') {
|
||||
return useQuery({
|
||||
queryKey: ['ddragon-manifest', locale],
|
||||
|
||||
@@ -247,3 +247,146 @@ export interface DdragonManifest {
|
||||
champions: Record<string, DdragonChampionEntry>;
|
||||
fetchedAt: string;
|
||||
}
|
||||
|
||||
export type RiotQueueGroup =
|
||||
| 'all'
|
||||
| 'summoners-rift'
|
||||
| 'aram'
|
||||
| 'urf'
|
||||
| 'arena';
|
||||
export type RiotRankFilter = 'all' | 'solo' | 'flex' | 'normal';
|
||||
|
||||
export interface ApiHistorySeason {
|
||||
id: string;
|
||||
label: string;
|
||||
startedAt: string | null;
|
||||
endedAt: string | null;
|
||||
}
|
||||
|
||||
export interface ApiUserHistoryProfile {
|
||||
userId: string;
|
||||
puuid: string;
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
profileIconId: number;
|
||||
summonerLevel: number;
|
||||
tiers: ApiTierInfo[];
|
||||
season: ApiHistorySeason;
|
||||
seasons: ApiHistorySeason[];
|
||||
lastFetchedAt: string | null;
|
||||
}
|
||||
|
||||
export interface ApiChampionStatsRow {
|
||||
championId: number;
|
||||
games: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
winRate: number;
|
||||
avgKills: number;
|
||||
avgDeaths: number;
|
||||
avgAssists: number;
|
||||
kda: number;
|
||||
totalKills: number;
|
||||
totalDeaths: number;
|
||||
totalAssists: number;
|
||||
doubleKills: number;
|
||||
tripleKills: number;
|
||||
quadraKills: number;
|
||||
pentaKills: number;
|
||||
avgCs: number;
|
||||
avgCsPerMin: number;
|
||||
}
|
||||
|
||||
export interface ApiChampionStatsResponse {
|
||||
queueGroup: RiotQueueGroup;
|
||||
rank: RiotRankFilter;
|
||||
queueIds: number[];
|
||||
season: ApiHistorySeason;
|
||||
lastFetchedAt: string | null;
|
||||
champions: ApiChampionStatsRow[];
|
||||
totals: ApiChampionStatsRow;
|
||||
}
|
||||
|
||||
export interface ApiRecentSummaryResponse {
|
||||
windowSize: number;
|
||||
winRate: number;
|
||||
wins: number;
|
||||
losses: number;
|
||||
streak: { type: 'win' | 'loss'; count: number } | null;
|
||||
kda: number;
|
||||
avgKills: number;
|
||||
avgDeaths: number;
|
||||
avgAssists: number;
|
||||
bestRating: {
|
||||
rating: number | 'Perfect';
|
||||
kills: number;
|
||||
deaths: number;
|
||||
assists: number;
|
||||
matchId: string;
|
||||
} | null;
|
||||
positionRates: Partial<Record<RiotLane, number>>;
|
||||
topChampions: Array<{
|
||||
championId: number;
|
||||
games: number;
|
||||
winRate: number;
|
||||
pickRate: number;
|
||||
avgRating: number;
|
||||
}>;
|
||||
lastFetchedAt: string | null;
|
||||
}
|
||||
|
||||
export interface ApiRecentMatchTeam {
|
||||
side: 100 | 200;
|
||||
win: boolean;
|
||||
objectives?: { baron?: number; dragon?: number; tower?: number };
|
||||
participants: Array<{
|
||||
puuid: string;
|
||||
gameName: string;
|
||||
tagLine: string;
|
||||
championId: number;
|
||||
teamPosition: string;
|
||||
kills: number;
|
||||
deaths: number;
|
||||
assists: number;
|
||||
}>;
|
||||
}
|
||||
|
||||
export interface ApiRecentMatchView {
|
||||
matchId: string;
|
||||
queueId: number;
|
||||
queueLabel: string;
|
||||
gameCreation: number;
|
||||
gameDuration: number;
|
||||
win: boolean;
|
||||
remake: boolean;
|
||||
championId: number;
|
||||
championLevel: number;
|
||||
teamPosition: string;
|
||||
kills: number;
|
||||
deaths: number;
|
||||
assists: number;
|
||||
kda: number;
|
||||
rating: number;
|
||||
totalCs: number;
|
||||
csPerMin: number;
|
||||
killParticipation: number;
|
||||
visionScore: number;
|
||||
controlWardsBought: number;
|
||||
wardsPlaced: number;
|
||||
wardsKilled: number;
|
||||
damageDealtToChampions: number;
|
||||
damageTaken: number;
|
||||
goldEarned: number;
|
||||
items: number[];
|
||||
trinket: number;
|
||||
summonerSpells: [number, number];
|
||||
perks: { primaryStyle?: number; subStyle?: number; keystone?: number };
|
||||
teams: ApiRecentMatchTeam[];
|
||||
}
|
||||
|
||||
export interface ApiRecentMatchesResponse {
|
||||
matches: ApiRecentMatchView[];
|
||||
nextCursor: number | null;
|
||||
lastFetchedAt: string | null;
|
||||
season: ApiHistorySeason;
|
||||
}
|
||||
Reference in new issue
Block a user