This commit is contained in:
dahyeon committed 2026-04-27 14:04:04 -07:00
1 parent 7a43a667f1
commit c00545f281
21 files changed
+1920 -5

No files matched your search

+79
View File
@@ -16,6 +16,7 @@ import type {
ApiMatch,
ApiRecentMatchesResponse,
ApiRecentSummaryResponse,
ApiTournamentCode,
ApiUserHistoryProfile,
DdragonManifest,
MatchStatus,
@@ -23,6 +24,11 @@ import type {
MeResponse,
RiotQueueGroup,
RiotRankFilter,
TournamentCodeBulkUploadResponse,
TournamentCodeListResponse,
TournamentCodeState,
TournamentCodeStatsResponse,
TournamentCodeUploadItem,
} from './types';
const DDRAGON_MANIFEST_STALE_MS = 24 * 60 * 60 * 1000;
@@ -253,6 +259,79 @@ export function useDdragonManifest(locale = 'ko_KR') {
});
}
export function useTournamentCodeStats(
communityId = DEFAULT_COMMUNITY_ID,
enabled = true,
) {
return useQuery({
queryKey: ['tournament-code-stats', communityId],
queryFn: () =>
apiFetch<TournamentCodeStatsResponse>(
`/communities/${communityId}/tournament-codes/stats`,
),
enabled: Boolean(communityId && enabled),
refetchInterval: enabled ? 30_000 : false,
retry: false,
});
}
export function useTournamentCodes(
options: { state?: TournamentCodeState; limit?: number },
communityId = DEFAULT_COMMUNITY_ID,
) {
return useQuery({
queryKey: [
'tournament-codes',
communityId,
options.state ?? null,
options.limit ?? null,
],
queryFn: () => {
const searchParams = new URLSearchParams();
if (options.state) searchParams.set('state', options.state);
if (options.limit) searchParams.set('limit', String(options.limit));
const queryString = searchParams.toString();
return apiFetch<TournamentCodeListResponse>(
`/communities/${communityId}/tournament-codes${queryString ? `?${queryString}` : ''}`,
);
},
enabled: Boolean(communityId),
refetchInterval: 30_000,
});
}
export function useBulkUploadTournamentCodes(communityId = DEFAULT_COMMUNITY_ID) {
return useMutation({
mutationFn: (codes: TournamentCodeUploadItem[]) =>
apiFetch<TournamentCodeBulkUploadResponse>(
`/communities/${communityId}/tournament-codes`,
{
method: 'POST',
body: JSON.stringify({ codes }),
},
),
});
}
export function useRestoreTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
return useMutation({
mutationFn: (codeId: string) =>
apiFetch<ApiTournamentCode>(
`/communities/${communityId}/tournament-codes/${codeId}/release`,
{ method: 'POST' },
),
});
}
export function useDeleteTournamentCode(communityId = DEFAULT_COMMUNITY_ID) {
return useMutation({
mutationFn: (codeId: string) =>
apiFetch<void>(`/communities/${communityId}/tournament-codes/${codeId}`, {
method: 'DELETE',
}),
});
}
export function useMe() {
const authUserId = useAuthUserId();
const { accounts, inProgress, instance } = useMsal();
+5
View File
@@ -12,6 +12,7 @@ import type {
Position,
RiotLane,
TeamSide,
TournamentCodeSlotView,
} from "./types";
import { POSITION_ORDER, sideLabel } from "../lib/league";
@@ -46,6 +47,8 @@ export interface MatchDetailView {
description: string;
map: string;
maxParticipants: number;
gameCount: number;
tournamentCodes: TournamentCodeSlotView[];
joined: boolean;
participants: ParticipantView[];
teams: TeamView[];
@@ -402,6 +405,8 @@ export function mapApiMatchToMatchDetail(match: ApiMatch): MatchDetailView {
description: match.description,
map: mapIdToLabel(match.mapId),
maxParticipants: match.maxParticipants,
gameCount: match.gameCount ?? 3,
tournamentCodes: match.tournamentCodes ?? [],
joined: Boolean(match.joined),
participants,
teams,
+71
View File
@@ -100,10 +100,28 @@ export interface ApiCommunity {
name: string;
description: string;
ownerUserId: string;
matchGameCount?: number;
createdAt: string;
updatedAt: string;
}
export type TournamentCodeState =
| 'available'
| 'reserved'
| 'used'
| 'expired'
| 'released';
export type TournamentCodeSlotState = TournamentCodeState | 'pending';
export interface TournamentCodeSlotView {
gameNumber: number;
code: string | null;
expiresAt: string | null;
state: TournamentCodeSlotState;
riotMatchId: string | null;
}
export interface ApiMatchParticipant {
userId: string;
puuid?: string;
@@ -150,6 +168,8 @@ export interface ApiMatch {
status: MatchStatus;
scheduledAt: string;
maxParticipants: number;
gameCount: number;
tournamentCodes?: TournamentCodeSlotView[];
hostUserId?: string;
participants: ApiMatchParticipant[];
teams: ApiMatchTeam[];
@@ -248,6 +268,57 @@ export interface DdragonManifest {
fetchedAt: string;
}
export type TournamentSpectatorType = 'NONE' | 'LOBBYONLY' | 'ALL';
export interface ApiTournamentCode {
_id: string;
code: string;
region: string;
mapType: 'SUMMONERS_RIFT';
teamSize: number;
spectatorType: TournamentSpectatorType;
metadata?: Record<string, unknown>;
expiresAt: string;
state: TournamentCodeState;
matchId?: string;
gameNumber?: number;
reservedAt?: string;
usedAt?: string;
releasedAt?: string;
riotMatchId?: string;
uploadedBy: string;
uploadedAt: string;
source?: string;
notes?: string;
createdAt: string;
updatedAt: string;
}
export interface TournamentCodeStatsResponse {
byState: Record<TournamentCodeState, number>;
expiringSoon: number;
available: number;
}
export interface TournamentCodeListResponse {
codes: ApiTournamentCode[];
}
export interface TournamentCodeUploadItem {
code: string;
expiresAt: string;
spectatorType?: TournamentSpectatorType;
metadata?: Record<string, unknown>;
source?: string;
notes?: string;
}
export interface TournamentCodeBulkUploadResponse {
inserted: number;
duplicates: string[];
invalid: Array<{ code: string; reason: string }>;
}
export type RiotQueueGroup =
| 'all'
| 'summoners-rift'