This commit is contained in:
dahyeon committed 2026-04-27 18:55:04 -07:00
1 parent 2250b6072e
commit 1bbfc901e8
17 files changed
+3471 -59

No files matched your search

+159 -3
View File
@@ -13,10 +13,15 @@ import type {
ApiChampionStatsResponse,
ApiCommunity,
ApiEnqueueRefreshResult,
ApiInternalMatchDetailResponse,
ApiInternalMatchListResponse,
ApiLeaderboardResponse,
ApiMatch,
ApiRecentMatchesResponse,
ApiRecentSummaryResponse,
ApiTeamInsightsResponse,
ApiTournamentCode,
ApiUserInternalHistoryResponse,
ApiUserHistoryProfile,
DdragonManifest,
MatchStatus,
@@ -45,6 +50,14 @@ export interface UserHistoryFilters {
championId?: number;
}
export interface CommunityInternalStatsFilters {
seasonId?: string;
from?: string;
to?: string;
championId?: number;
limit?: number;
}
function createMatchesPath(
communityId: string,
options: MatchesQueryOptions = {},
@@ -153,6 +166,7 @@ export function useChampionStats(
userId: string | undefined,
filters: UserHistoryFilters,
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useQuery({
queryKey: [
@@ -168,7 +182,7 @@ export function useChampionStats(
createUserHistoryPath(communityId, userId ?? '', 'champion-stats', filters),
{ auth: 'none' },
),
enabled: Boolean(communityId && userId),
enabled: Boolean(communityId && userId && enabled),
});
}
@@ -176,6 +190,7 @@ export function useRecentSummary(
userId: string | undefined,
filters: UserHistoryFilters,
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useQuery({
queryKey: [
@@ -192,7 +207,7 @@ export function useRecentSummary(
createUserHistoryPath(communityId, userId ?? '', 'recent-summary', filters),
{ auth: 'none' },
),
enabled: Boolean(communityId && userId),
enabled: Boolean(communityId && userId && enabled),
});
}
@@ -200,6 +215,7 @@ export function useRecentMatches(
userId: string | undefined,
filters: UserHistoryFilters,
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useInfiniteQuery({
queryKey: [
@@ -221,7 +237,147 @@ export function useRecentMatches(
),
initialPageParam: null as number | null,
getNextPageParam: (lastPage) => lastPage.nextCursor,
enabled: Boolean(communityId && userId),
enabled: Boolean(communityId && userId && enabled),
});
}
function createCommunityInternalStatsPath(
communityId: string,
resource: string,
filters: CommunityInternalStatsFilters = {},
extra: Record<string, string | number | null | undefined> = {},
) {
const searchParams = new URLSearchParams();
if (filters.seasonId) searchParams.set('seasonId', filters.seasonId);
if (filters.from) searchParams.set('from', filters.from);
if (filters.to) searchParams.set('to', filters.to);
if (filters.championId) searchParams.set('championId', String(filters.championId));
if (filters.limit) searchParams.set('limit', String(filters.limit));
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}/internal-stats/${resource}${queryString ? `?${queryString}` : ''}`;
}
export function useCommunityInternalStatsMatches(
filters: CommunityInternalStatsFilters,
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useInfiniteQuery({
queryKey: [
'community-internal-stats-matches',
communityId,
filters.seasonId ?? null,
filters.from ?? null,
filters.to ?? null,
filters.championId ?? null,
filters.limit ?? null,
],
queryFn: ({ pageParam }) =>
apiFetch<ApiInternalMatchListResponse>(
createCommunityInternalStatsPath(communityId, 'matches', filters, {
cursor: pageParam,
}),
{ auth: 'none' },
),
initialPageParam: null as number | null,
getNextPageParam: (lastPage) => lastPage.nextCursor,
enabled: Boolean(communityId && enabled),
});
}
export function useCommunityLeaderboard(
filters: CommunityInternalStatsFilters,
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useQuery({
queryKey: [
'community-internal-stats-leaderboard',
communityId,
filters.seasonId ?? null,
filters.from ?? null,
filters.to ?? null,
filters.championId ?? null,
],
queryFn: () =>
apiFetch<ApiLeaderboardResponse>(
createCommunityInternalStatsPath(communityId, 'leaderboard', filters),
{ auth: 'none' },
),
enabled: Boolean(communityId && enabled),
});
}
export function useTeamInsights(
filters: CommunityInternalStatsFilters,
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useQuery({
queryKey: [
'community-internal-stats-team-insights',
communityId,
filters.seasonId ?? null,
filters.from ?? null,
filters.to ?? null,
filters.championId ?? null,
],
queryFn: () =>
apiFetch<ApiTeamInsightsResponse>(
createCommunityInternalStatsPath(communityId, 'team-insights', filters),
{ auth: 'none' },
),
enabled: Boolean(communityId && enabled),
});
}
export function useInternalMatchDetail(
matchId: string | undefined,
communityId = DEFAULT_COMMUNITY_ID,
) {
return useQuery({
queryKey: ['community-internal-stats-match', communityId, matchId ?? null],
queryFn: () =>
apiFetch<ApiInternalMatchDetailResponse>(
`/communities/${communityId}/internal-stats/match/${matchId}`,
{ auth: 'none' },
),
enabled: Boolean(communityId && matchId),
retry: false,
});
}
export function useUserInternalHistory(
userId: string | undefined,
filters: UserHistoryFilters,
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useInfiniteQuery({
queryKey: [
'user-internal-history',
communityId,
userId ?? null,
filters.seasonId ?? null,
filters.championId ?? null,
],
queryFn: ({ pageParam }) =>
apiFetch<ApiUserInternalHistoryResponse>(
createUserHistoryPath(communityId, userId ?? '', 'internal-history', filters, {
cursor: pageParam,
limit: 10,
}),
{ auth: 'none' },
),
initialPageParam: null as number | null,
getNextPageParam: (lastPage) => lastPage.nextCursor,
enabled: Boolean(communityId && userId && enabled),
});
}
+132 -1
View File
@@ -344,7 +344,8 @@ export type RiotQueueGroup =
| 'summoners-rift'
| 'aram'
| 'urf'
| 'arena';
| 'arena'
| 'internal';
export type RiotRankFilter = 'all' | 'solo' | 'flex' | 'normal';
export interface ApiHistorySeason {
@@ -482,6 +483,136 @@ export interface ApiRecentMatchesResponse {
season: ApiHistorySeason;
}
export interface ApiInternalMatchCard {
matchId: string;
title: string;
scheduledAt: string;
status: 'finished' | 'in-progress';
gameCount: number;
blueScore: number;
redScore: number;
winnerSide?: TeamSide;
games: Array<{
gameNumber: number;
riotMatchId: string | null;
winnerSide: TeamSide | null;
gameDuration: number;
}>;
teams: Array<{
side: TeamSide;
name: string;
members: Array<{
userId: string;
summonerName: string;
profileIconId: number;
}>;
}>;
}
export interface ApiInternalMatchListResponse {
matches: ApiInternalMatchCard[];
nextCursor: number | null;
season: ApiHistorySeason;
}
export interface ApiLeaderboardRow {
userId: string;
summonerName: string;
profileIconId: number;
games: number;
wins: number;
losses: number;
winRate: number;
totalKills: number;
totalDeaths: number;
totalAssists: number;
kda: number;
avgGoldPerMin: number;
avgKillParticipation: number;
avgCsPerMin: number;
avgDamageShare: number;
avgVisionScore: number;
byLane: Partial<Record<RiotLane, { games: number; wins: number; kda: number }>>;
topChampions: Array<{ championId: number; games: number; winRate: number }>;
}
export interface ApiLeaderboardResponse {
rows: ApiLeaderboardRow[];
season: ApiHistorySeason;
}
export interface ApiLeaderHighlight {
metric: number;
userId: string;
summonerName: string;
championId?: number;
matchId?: string;
isSingleGame: boolean;
}
export interface ApiTeamInsightsResponse {
season: ApiHistorySeason;
sideWinRate: {
blue: number;
red: number;
bluePicks: number;
redPicks: number;
};
topKda: ApiLeaderHighlight | null;
mostKills: ApiLeaderHighlight | null;
topTeamGpm: ApiLeaderHighlight | null;
topKillParticipation: ApiLeaderHighlight | null;
bestFarm: ApiLeaderHighlight | null;
minGamesThreshold: number;
}
export interface ApiInternalMatchDetailResponse {
match: ApiInternalMatchCard;
games: Array<{
gameNumber: number;
riotMatchId: string;
gameCreation: number;
gameDuration: number;
teams: Array<{
side: TeamSide;
win: boolean;
objectives: { baron: number; dragon: number; tower: number };
participants: Array<{
userId: string | null;
summonerName: string;
side: TeamSide;
teamPosition: string;
championId: number;
kills: number;
deaths: number;
assists: number;
cs: number;
csPerMin: number;
gold: number;
gpm: number;
damageDealtToChampions: number;
damageShare: number;
killParticipation: number;
visionScore: number;
items: number[];
trinket: number;
summonerSpells: [number, number];
perks: { primaryStyle?: number; subStyle?: number; keystone?: number };
win: boolean;
}>;
}>;
}>;
}
export interface ApiUserInternalHistoryResponse {
season: ApiHistorySeason;
championStats: ApiChampionStatsResponse;
summary: ApiRecentSummaryResponse;
matches: ApiRecentMatchView[];
nextCursor: number | null;
lastFetchedAt: string | null;
}
export type ApiRiotJobPriority = 'high' | 'low';
export type ApiRiotJobState = 'queued' | 'processing' | 'completed' | 'failed';