Skip to content

Commit 0df94dd

Browse files
authored
Add stages and clubs typing (#1489)
1 parent f8458b9 commit 0df94dd

File tree

8 files changed

+31
-19
lines changed

8 files changed

+31
-19
lines changed

frontend/src/components/brackets/courts.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { Grid, Title } from '@mantine/core';
22
import { SWRResponse } from 'swr';
33

44
import { TournamentMinimal } from '@components/utils/tournament';
5-
import { RoundWithMatches } from '@openapi';
5+
import { RoundWithMatches, StagesWithStageItemsResponse } from '@openapi';
66
import { getStages } from '@services/adapter';
77
import Match from './match';
88

99
function getRoundsGridCols(
10-
swrStagesResponse: SWRResponse,
10+
swrStagesResponse: SWRResponse<StagesWithStageItemsResponse>,
1111
activeRound: RoundWithMatches,
1212
tournamentData: TournamentMinimal
1313
) {

frontend/src/components/builder/builder.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import {
3535
StageItemInputOption,
3636
formatStageItemInputTentative,
3737
} from '@components/utils/stage_item_input';
38-
import { responseIsValid } from '@components/utils/util';
3938
import {
4039
Ranking,
4140
StageItemInputOptionsResponse,
@@ -162,7 +161,7 @@ function StageItemInputComboBox({
162161
}
163162

164163
export function getAvailableInputs(
165-
swrAvailableInputsResponse: SWRResponse,
164+
swrAvailableInputsResponse: SWRResponse<StageItemInputOptionsResponse>,
166165
teamsMap: any,
167166
stageItemMap: any
168167
) {
@@ -193,9 +192,9 @@ export function getAvailableInputs(
193192
already_taken: option.already_taken,
194193
};
195194
};
196-
return responseIsValid(swrAvailableInputsResponse)
197-
? Object.keys(swrAvailableInputsResponse.data.data).reduce((result: any, stage_id: string) => {
198-
const option = swrAvailableInputsResponse.data.data[stage_id];
195+
return swrAvailableInputsResponse.data != undefined
196+
? Object.keys(swrAvailableInputsResponse.data?.data).reduce((result: any, stage_id: string) => {
197+
const option = assert_not_none(swrAvailableInputsResponse.data?.data[stage_id]);
199198
result[stage_id] = option
200199
.map((opt: StageItemInputOption) => getComboBoxOptionForStageItemInput(opt))
201200
.filter((o: StageItemInputOption | null) => o != null);

frontend/src/components/modals/activate_next_stage_modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export default function ActivateNextStageModal({
7474
}: {
7575
tournamentId: number;
7676
swrStagesResponse: SWRResponse<StagesWithStageItemsResponse>;
77-
swrRankingsPerStageItemResponse: SWRResponse;
77+
swrRankingsPerStageItemResponse: SWRResponse<StageRankingResponse>;
7878
}) {
7979
const { t } = useTranslation();
8080
const [opened, setOpened] = useState(false);

frontend/src/components/modals/tournament_modal.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ export default function TournamentModal({
180180
const { t } = useTranslation();
181181
const [opened, setOpened] = useState(false);
182182
const operation_text = t('create_tournament_button');
183-
const swrClubsResponse: SWRResponse = getClubs();
184-
const clubs: Club[] = swrClubsResponse.data != null ? swrClubsResponse.data.data : [];
183+
const swrClubsResponse = getClubs();
184+
const clubs = swrClubsResponse.data?.data || [];
185185

186186
return (
187187
<>

frontend/src/components/tables/clubs.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import ClubModal from '@components/modals/club_modal';
77
import { EmptyTableInfo } from '@components/no_content/empty_table_info';
88
import RequestErrorAlert from '@components/utils/error_alert';
99
import { TableSkeletonSingleColumn } from '@components/utils/skeletons';
10-
import { Club } from '@openapi';
10+
import { Club, ClubsResponse } from '@openapi';
1111
import { deleteClub } from '@services/club';
1212
import TableLayout, { ThNotSortable, ThSortable, getTableState, sortTableEntries } from './table';
1313

14-
export default function ClubsTable({ swrClubsResponse }: { swrClubsResponse: SWRResponse }) {
14+
export default function ClubsTable({
15+
swrClubsResponse,
16+
}: {
17+
swrClubsResponse: SWRResponse<ClubsResponse>;
18+
}) {
1519
const clubs: Club[] = swrClubsResponse.data != null ? swrClubsResponse.data.data : [];
1620
const tableState = getTableState('name');
1721
const { t } = useTranslation();
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { SWRResponse } from 'swr';
22

3-
import { StageWithStageItems } from '@openapi';
3+
import { StagesWithStageItemsResponse } from '@openapi';
44

5-
export function getStageById(swrStagesResponse: SWRResponse, stageId: number) {
6-
return swrStagesResponse.data.data.filter((stage: StageWithStageItems) => stage.id === stageId);
5+
export function getStageById(
6+
swrStagesResponse: SWRResponse<StagesWithStageItemsResponse>,
7+
stageId: number
8+
) {
9+
return (swrStagesResponse.data?.data || []).filter((stage) => stage.id === stageId);
710
}

frontend/src/pages/tournaments/[id]/stages/swiss/[stage_item_id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export default function SwissTournamentPage() {
209209
displaySettings={displaySettings}
210210
swrUpcomingMatchesResponse={swrUpcomingMatchesResponse}
211211
/>
212-
{showScheduler ? (
212+
{showScheduler && activeStage ? (
213213
<Scheduler
214214
activeStage={activeStage}
215215
draftRound={draftRound}

frontend/src/services/lookups.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import { SWRResponse } from 'swr';
22

33
import { assert_not_none } from '@components/utils/assert';
44
import { groupBy, responseIsValid } from '@components/utils/util';
5-
import { Court, FullTeamWithPlayers, MatchWithDetails, StageWithStageItems } from '@openapi';
5+
import {
6+
Court,
7+
CourtsResponse,
8+
FullTeamWithPlayers,
9+
MatchWithDetails,
10+
StageWithStageItems,
11+
} from '@openapi';
612
import { getTeams } from './adapter';
713

814
export function getTeamsLookup(tournamentId: number) {
@@ -114,10 +120,10 @@ export function getMatchLookupByCourt(swrStagesResponse: SWRResponse) {
114120
}
115121

116122
export function getScheduleData(
117-
swrCourtsResponse: SWRResponse,
123+
swrCourtsResponse: SWRResponse<CourtsResponse>,
118124
matchesByCourtId: any
119125
): { court: Court; matches: MatchWithDetails[] }[] {
120-
return swrCourtsResponse.data.data.map((court: Court) => ({
126+
return (swrCourtsResponse.data?.data || []).map((court: Court) => ({
121127
matches: (matchesByCourtId[court.id] || [])
122128
.filter((match: MatchWithDetails) => match.start_time != null)
123129
.sort((m1: MatchWithDetails, m2: MatchWithDetails) => {

0 commit comments

Comments
 (0)