refactor: cut web results over to competition projections
This commit is contained in:
1 parent
7db97c540b
commit
6bddb666fc
13 files changed
+2153
-3885
No files matched your search
+205
-131
@@ -1,6 +1,16 @@
|
||||
import { InteractionStatus } from '@azure/msal-browser';
|
||||
import { useMsal } from '@azure/msal-react';
|
||||
import { useInfiniteQuery, useMutation, useQuery } from '@tanstack/react-query';
|
||||
import type {
|
||||
CompetitionCommandResponse,
|
||||
CompetitionDetailResponse,
|
||||
CreateSeriesAdjudicationRequest,
|
||||
ReverseSeriesResultRequest,
|
||||
SeriesId,
|
||||
SeriesReversalPreviewRequest,
|
||||
SeriesReversalPreviewResponse,
|
||||
TeamCompetitionViewResponse,
|
||||
} from '@lolympus/contracts';
|
||||
import { DEFAULT_COMMUNITY_ID, useAuthUserId } from '../config';
|
||||
import { apiFetch } from '../lib/api';
|
||||
import {
|
||||
@@ -41,7 +51,6 @@ import type {
|
||||
RebuildLegacyMatchesResponse,
|
||||
TournamentCodeBulkUploadResponse,
|
||||
TournamentCodeListResponse,
|
||||
TournamentCodeSlotView,
|
||||
TournamentCodeState,
|
||||
TournamentCodeStatsResponse,
|
||||
TournamentCodeUploadItem,
|
||||
@@ -83,7 +92,8 @@ function createMatchesPath(
|
||||
if (options.limit) searchParams.set('limit', String(options.limit));
|
||||
if (options.page) searchParams.set('page', String(options.page));
|
||||
if (options.offset) searchParams.set('offset', String(options.offset));
|
||||
if (options.scheduledFrom) searchParams.set('scheduledFrom', options.scheduledFrom);
|
||||
if (options.scheduledFrom)
|
||||
searchParams.set('scheduledFrom', options.scheduledFrom);
|
||||
if (options.scheduledTo) searchParams.set('scheduledTo', options.scheduledTo);
|
||||
if (options.sort) searchParams.set('sort', options.sort);
|
||||
|
||||
@@ -152,7 +162,10 @@ export function useMatchesPage(
|
||||
});
|
||||
}
|
||||
|
||||
export function useMatch(matchId: string | undefined, communityId = DEFAULT_COMMUNITY_ID) {
|
||||
export function useMatch(
|
||||
matchId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['match', communityId, matchId ?? null],
|
||||
queryFn: () =>
|
||||
@@ -164,6 +177,126 @@ export function useMatch(matchId: string | undefined, communityId = DEFAULT_COMM
|
||||
});
|
||||
}
|
||||
|
||||
export function useCompetition(
|
||||
matchId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
enabled = true,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['competition', communityId, matchId ?? null],
|
||||
queryFn: () =>
|
||||
apiFetch<CompetitionDetailResponse>(
|
||||
`/communities/${communityId}/matches/${matchId}/competition`,
|
||||
{
|
||||
auth: 'none',
|
||||
},
|
||||
),
|
||||
enabled: enabled && Boolean(communityId && matchId),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTeamCompetition(
|
||||
matchId: string | undefined,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useQuery({
|
||||
queryKey: ['competition-team', communityId, matchId ?? null],
|
||||
queryFn: () =>
|
||||
apiFetch<TeamCompetitionViewResponse>(
|
||||
`/communities/${communityId}/matches/${matchId}/competition/team`,
|
||||
),
|
||||
enabled: Boolean(communityId && matchId),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
type CompetitionMutationScope = {
|
||||
matchId: string;
|
||||
seriesId: SeriesId;
|
||||
revision: number;
|
||||
};
|
||||
|
||||
type IdempotentCompetitionMutationScope = CompetitionMutationScope & {
|
||||
idempotencyKey: string;
|
||||
};
|
||||
|
||||
function competitionCommandHeaders(revision: number, idempotencyKey?: string) {
|
||||
return {
|
||||
'If-Match': `"${revision}"`,
|
||||
...(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function useAdjudicateCompetitionSeries(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (
|
||||
params: IdempotentCompetitionMutationScope & {
|
||||
request: CreateSeriesAdjudicationRequest;
|
||||
},
|
||||
) =>
|
||||
apiFetch<CompetitionCommandResponse>(
|
||||
`/communities/${communityId}/matches/${params.matchId}/competition/series/${params.seriesId}/adjudications`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: competitionCommandHeaders(
|
||||
params.revision,
|
||||
params.idempotencyKey,
|
||||
),
|
||||
body: JSON.stringify(params.request),
|
||||
},
|
||||
),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function usePreviewCompetitionSeriesReversal(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (
|
||||
params: CompetitionMutationScope & {
|
||||
request: SeriesReversalPreviewRequest;
|
||||
},
|
||||
) =>
|
||||
apiFetch<SeriesReversalPreviewResponse>(
|
||||
`/communities/${communityId}/matches/${params.matchId}/competition/series/${params.seriesId}/reversal-preview`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: competitionCommandHeaders(params.revision),
|
||||
body: JSON.stringify(params.request),
|
||||
},
|
||||
),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useReverseCompetitionSeries(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (
|
||||
params: IdempotentCompetitionMutationScope & {
|
||||
request: ReverseSeriesResultRequest;
|
||||
},
|
||||
) =>
|
||||
apiFetch<CompetitionCommandResponse>(
|
||||
`/communities/${communityId}/matches/${params.matchId}/competition/series/${params.seriesId}/reverse`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: competitionCommandHeaders(
|
||||
params.revision,
|
||||
params.idempotencyKey,
|
||||
),
|
||||
body: JSON.stringify(params.request),
|
||||
},
|
||||
),
|
||||
retry: false,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCommunityUserSearch(
|
||||
query: string,
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
@@ -302,7 +435,13 @@ export function useCreateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
|
||||
export function useUpdateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: ({ matchId, body }: { matchId: string; body: Partial<MatchMutationRequest> }) =>
|
||||
mutationFn: ({
|
||||
matchId,
|
||||
body,
|
||||
}: {
|
||||
matchId: string;
|
||||
body: Partial<MatchMutationRequest>;
|
||||
}) =>
|
||||
apiFetch<ApiMatch>(`/communities/${communityId}/matches/${matchId}`, {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify(body),
|
||||
@@ -310,101 +449,6 @@ export function useUpdateMatch(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useReshuffleDoubleEliminationSeeds(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (matchId: string) =>
|
||||
apiFetch<ApiMatch>(
|
||||
`/communities/${communityId}/matches/${matchId}/double-elimination/seeds/reshuffle`,
|
||||
{ method: 'POST' },
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useSwapDoubleEliminationSeeds(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (params: {
|
||||
matchId: string;
|
||||
leftSeedNumber: number;
|
||||
rightSeedNumber: number;
|
||||
}) =>
|
||||
apiFetch<ApiMatch>(
|
||||
`/communities/${communityId}/matches/${params.matchId}/double-elimination/seeds/swap`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
leftSeedNumber: params.leftSeedNumber,
|
||||
rightSeedNumber: params.rightSeedNumber,
|
||||
}),
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useApplyDoubleEliminationWalkover(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (params: {
|
||||
matchId: string;
|
||||
bracketMatchId: string;
|
||||
winnerTeamIndex: number;
|
||||
reason?: string;
|
||||
}) =>
|
||||
apiFetch<ApiMatch>(
|
||||
`/communities/${communityId}/matches/${params.matchId}/double-elimination/bracket-matches/${params.bracketMatchId}/walkover`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
winnerTeamIndex: params.winnerTeamIndex,
|
||||
reason: params.reason,
|
||||
}),
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCancelDoubleEliminationWalkover(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (params: {
|
||||
matchId: string;
|
||||
bracketMatchId: string;
|
||||
reason?: string;
|
||||
}) =>
|
||||
apiFetch<ApiMatch>(
|
||||
`/communities/${communityId}/matches/${params.matchId}/double-elimination/bracket-matches/${params.bracketMatchId}/walkover/cancel`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ reason: params.reason }),
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCancelDoubleEliminationRiotResult(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (params: {
|
||||
matchId: string;
|
||||
bracketMatchId: string;
|
||||
reason?: string;
|
||||
}) =>
|
||||
apiFetch<ApiMatch>(
|
||||
`/communities/${communityId}/matches/${params.matchId}/double-elimination/bracket-matches/${params.bracketMatchId}/result/cancel`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ reason: params.reason }),
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
function createUserHistoryPath(
|
||||
communityId: string,
|
||||
userId: string,
|
||||
@@ -416,7 +460,8 @@ function createUserHistoryPath(
|
||||
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));
|
||||
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));
|
||||
@@ -461,8 +506,15 @@ export function useChampionStats(
|
||||
],
|
||||
queryFn: () =>
|
||||
apiFetch<ApiChampionStatsResponse>(
|
||||
createUserHistoryPath(communityId, userId ?? '', 'champion-stats', filters),
|
||||
{ auth: 'none' },
|
||||
createUserHistoryPath(
|
||||
communityId,
|
||||
userId ?? '',
|
||||
'champion-stats',
|
||||
filters,
|
||||
),
|
||||
{
|
||||
auth: 'none',
|
||||
},
|
||||
),
|
||||
enabled: Boolean(communityId && userId && enabled),
|
||||
});
|
||||
@@ -486,8 +538,15 @@ export function useRecentSummary(
|
||||
],
|
||||
queryFn: () =>
|
||||
apiFetch<ApiRecentSummaryResponse>(
|
||||
createUserHistoryPath(communityId, userId ?? '', 'recent-summary', filters),
|
||||
{ auth: 'none' },
|
||||
createUserHistoryPath(
|
||||
communityId,
|
||||
userId ?? '',
|
||||
'recent-summary',
|
||||
filters,
|
||||
),
|
||||
{
|
||||
auth: 'none',
|
||||
},
|
||||
),
|
||||
enabled: Boolean(communityId && userId && enabled),
|
||||
});
|
||||
@@ -511,10 +570,16 @@ export function useRecentMatches(
|
||||
],
|
||||
queryFn: ({ pageParam }) =>
|
||||
apiFetch<ApiRecentMatchesResponse>(
|
||||
createUserHistoryPath(communityId, userId ?? '', 'recent-matches', filters, {
|
||||
cursor: pageParam,
|
||||
limit: 10,
|
||||
}),
|
||||
createUserHistoryPath(
|
||||
communityId,
|
||||
userId ?? '',
|
||||
'recent-matches',
|
||||
filters,
|
||||
{
|
||||
cursor: pageParam,
|
||||
limit: 10,
|
||||
},
|
||||
),
|
||||
{ auth: 'none' },
|
||||
),
|
||||
initialPageParam: null as number | null,
|
||||
@@ -533,7 +598,8 @@ function createCommunityInternalStatsPath(
|
||||
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.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 !== '') {
|
||||
@@ -590,7 +656,9 @@ export function useCommunityLeaderboard(
|
||||
queryFn: () =>
|
||||
apiFetch<ApiLeaderboardResponse>(
|
||||
createCommunityInternalStatsPath(communityId, 'leaderboard', filters),
|
||||
{ auth: 'none' },
|
||||
{
|
||||
auth: 'none',
|
||||
},
|
||||
),
|
||||
enabled: Boolean(communityId && enabled),
|
||||
});
|
||||
@@ -613,7 +681,9 @@ export function useTeamInsights(
|
||||
queryFn: () =>
|
||||
apiFetch<ApiTeamInsightsResponse>(
|
||||
createCommunityInternalStatsPath(communityId, 'team-insights', filters),
|
||||
{ auth: 'none' },
|
||||
{
|
||||
auth: 'none',
|
||||
},
|
||||
),
|
||||
enabled: Boolean(communityId && enabled),
|
||||
});
|
||||
@@ -628,7 +698,9 @@ export function useInternalMatchDetail(
|
||||
queryFn: () =>
|
||||
apiFetch<ApiInternalMatchDetailResponse>(
|
||||
`/communities/${communityId}/internal-stats/match/${matchId}`,
|
||||
{ auth: 'none' },
|
||||
{
|
||||
auth: 'none',
|
||||
},
|
||||
),
|
||||
enabled: Boolean(communityId && matchId),
|
||||
retry: false,
|
||||
@@ -651,10 +723,16 @@ export function useUserInternalHistory(
|
||||
],
|
||||
queryFn: ({ pageParam }) =>
|
||||
apiFetch<ApiUserInternalHistoryResponse>(
|
||||
createUserHistoryPath(communityId, userId ?? '', 'internal-history', filters, {
|
||||
cursor: pageParam,
|
||||
limit: 10,
|
||||
}),
|
||||
createUserHistoryPath(
|
||||
communityId,
|
||||
userId ?? '',
|
||||
'internal-history',
|
||||
filters,
|
||||
{
|
||||
cursor: pageParam,
|
||||
limit: 10,
|
||||
},
|
||||
),
|
||||
{ auth: 'none' },
|
||||
),
|
||||
initialPageParam: null as number | null,
|
||||
@@ -740,7 +818,9 @@ export function useTournamentCodes(
|
||||
});
|
||||
}
|
||||
|
||||
export function useBulkUploadTournamentCodes(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
export function useBulkUploadTournamentCodes(
|
||||
communityId = DEFAULT_COMMUNITY_ID,
|
||||
) {
|
||||
return useMutation({
|
||||
mutationFn: (codes: TournamentCodeUploadItem[]) =>
|
||||
apiFetch<TournamentCodeBulkUploadResponse>(
|
||||
@@ -772,16 +852,6 @@ export function useDeleteTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
});
|
||||
}
|
||||
|
||||
export function useReplaceTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: (params: { matchId: string; gameNumber: number }) =>
|
||||
apiFetch<TournamentCodeSlotView>(
|
||||
`/communities/${communityId}/tournament-codes/matches/${params.matchId}/games/${params.gameNumber}/replace`,
|
||||
{ method: 'POST' },
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
export function usePollTournamentResult(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
return useMutation({
|
||||
mutationFn: (matchId: string) =>
|
||||
@@ -791,9 +861,12 @@ export function usePollTournamentResult(communityId = DEFAULT_COMMUNITY_ID) {
|
||||
priority: 'high' | 'low';
|
||||
attempt: number;
|
||||
expandedToAllPuuids: boolean;
|
||||
}>(`/communities/${communityId}/matches/${matchId}/poll-tournament-result`, {
|
||||
method: 'POST',
|
||||
}),
|
||||
}>(
|
||||
`/communities/${communityId}/matches/${matchId}/poll-tournament-result`,
|
||||
{
|
||||
method: 'POST',
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -848,7 +921,8 @@ export function useLegacyImportMembers(
|
||||
],
|
||||
queryFn: () => {
|
||||
const searchParams = new URLSearchParams();
|
||||
if (options.windowStart) searchParams.set('windowStart', options.windowStart);
|
||||
if (options.windowStart)
|
||||
searchParams.set('windowStart', options.windowStart);
|
||||
if (options.windowEnd) searchParams.set('windowEnd', options.windowEnd);
|
||||
const queryString = searchParams.toString();
|
||||
return apiFetch<LegacyImportMembersResponse>(
|
||||
|
||||
Reference in new issue
Block a user