mirror of
https://github.com/evroon/bracket.git
synced 2026-04-29 03:25:44 -04:00
Add stages and clubs typing (#1489)
This commit is contained in:
@@ -2,12 +2,12 @@ import { Grid, Title } from '@mantine/core';
|
||||
import { SWRResponse } from 'swr';
|
||||
|
||||
import { TournamentMinimal } from '@components/utils/tournament';
|
||||
import { RoundWithMatches } from '@openapi';
|
||||
import { RoundWithMatches, StagesWithStageItemsResponse } from '@openapi';
|
||||
import { getStages } from '@services/adapter';
|
||||
import Match from './match';
|
||||
|
||||
function getRoundsGridCols(
|
||||
swrStagesResponse: SWRResponse,
|
||||
swrStagesResponse: SWRResponse<StagesWithStageItemsResponse>,
|
||||
activeRound: RoundWithMatches,
|
||||
tournamentData: TournamentMinimal
|
||||
) {
|
||||
|
||||
@@ -35,7 +35,6 @@ import {
|
||||
StageItemInputOption,
|
||||
formatStageItemInputTentative,
|
||||
} from '@components/utils/stage_item_input';
|
||||
import { responseIsValid } from '@components/utils/util';
|
||||
import {
|
||||
Ranking,
|
||||
StageItemInputOptionsResponse,
|
||||
@@ -162,7 +161,7 @@ function StageItemInputComboBox({
|
||||
}
|
||||
|
||||
export function getAvailableInputs(
|
||||
swrAvailableInputsResponse: SWRResponse,
|
||||
swrAvailableInputsResponse: SWRResponse<StageItemInputOptionsResponse>,
|
||||
teamsMap: any,
|
||||
stageItemMap: any
|
||||
) {
|
||||
@@ -193,9 +192,9 @@ export function getAvailableInputs(
|
||||
already_taken: option.already_taken,
|
||||
};
|
||||
};
|
||||
return responseIsValid(swrAvailableInputsResponse)
|
||||
? Object.keys(swrAvailableInputsResponse.data.data).reduce((result: any, stage_id: string) => {
|
||||
const option = swrAvailableInputsResponse.data.data[stage_id];
|
||||
return swrAvailableInputsResponse.data != undefined
|
||||
? Object.keys(swrAvailableInputsResponse.data?.data).reduce((result: any, stage_id: string) => {
|
||||
const option = assert_not_none(swrAvailableInputsResponse.data?.data[stage_id]);
|
||||
result[stage_id] = option
|
||||
.map((opt: StageItemInputOption) => getComboBoxOptionForStageItemInput(opt))
|
||||
.filter((o: StageItemInputOption | null) => o != null);
|
||||
|
||||
@@ -74,7 +74,7 @@ export default function ActivateNextStageModal({
|
||||
}: {
|
||||
tournamentId: number;
|
||||
swrStagesResponse: SWRResponse<StagesWithStageItemsResponse>;
|
||||
swrRankingsPerStageItemResponse: SWRResponse;
|
||||
swrRankingsPerStageItemResponse: SWRResponse<StageRankingResponse>;
|
||||
}) {
|
||||
const { t } = useTranslation();
|
||||
const [opened, setOpened] = useState(false);
|
||||
|
||||
@@ -180,8 +180,8 @@ export default function TournamentModal({
|
||||
const { t } = useTranslation();
|
||||
const [opened, setOpened] = useState(false);
|
||||
const operation_text = t('create_tournament_button');
|
||||
const swrClubsResponse: SWRResponse = getClubs();
|
||||
const clubs: Club[] = swrClubsResponse.data != null ? swrClubsResponse.data.data : [];
|
||||
const swrClubsResponse = getClubs();
|
||||
const clubs = swrClubsResponse.data?.data || [];
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -7,11 +7,15 @@ import ClubModal from '@components/modals/club_modal';
|
||||
import { EmptyTableInfo } from '@components/no_content/empty_table_info';
|
||||
import RequestErrorAlert from '@components/utils/error_alert';
|
||||
import { TableSkeletonSingleColumn } from '@components/utils/skeletons';
|
||||
import { Club } from '@openapi';
|
||||
import { Club, ClubsResponse } from '@openapi';
|
||||
import { deleteClub } from '@services/club';
|
||||
import TableLayout, { ThNotSortable, ThSortable, getTableState, sortTableEntries } from './table';
|
||||
|
||||
export default function ClubsTable({ swrClubsResponse }: { swrClubsResponse: SWRResponse }) {
|
||||
export default function ClubsTable({
|
||||
swrClubsResponse,
|
||||
}: {
|
||||
swrClubsResponse: SWRResponse<ClubsResponse>;
|
||||
}) {
|
||||
const clubs: Club[] = swrClubsResponse.data != null ? swrClubsResponse.data.data : [];
|
||||
const tableState = getTableState('name');
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { SWRResponse } from 'swr';
|
||||
|
||||
import { StageWithStageItems } from '@openapi';
|
||||
import { StagesWithStageItemsResponse } from '@openapi';
|
||||
|
||||
export function getStageById(swrStagesResponse: SWRResponse, stageId: number) {
|
||||
return swrStagesResponse.data.data.filter((stage: StageWithStageItems) => stage.id === stageId);
|
||||
export function getStageById(
|
||||
swrStagesResponse: SWRResponse<StagesWithStageItemsResponse>,
|
||||
stageId: number
|
||||
) {
|
||||
return (swrStagesResponse.data?.data || []).filter((stage) => stage.id === stageId);
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ export default function SwissTournamentPage() {
|
||||
displaySettings={displaySettings}
|
||||
swrUpcomingMatchesResponse={swrUpcomingMatchesResponse}
|
||||
/>
|
||||
{showScheduler ? (
|
||||
{showScheduler && activeStage ? (
|
||||
<Scheduler
|
||||
activeStage={activeStage}
|
||||
draftRound={draftRound}
|
||||
|
||||
@@ -2,7 +2,13 @@ import { SWRResponse } from 'swr';
|
||||
|
||||
import { assert_not_none } from '@components/utils/assert';
|
||||
import { groupBy, responseIsValid } from '@components/utils/util';
|
||||
import { Court, FullTeamWithPlayers, MatchWithDetails, StageWithStageItems } from '@openapi';
|
||||
import {
|
||||
Court,
|
||||
CourtsResponse,
|
||||
FullTeamWithPlayers,
|
||||
MatchWithDetails,
|
||||
StageWithStageItems,
|
||||
} from '@openapi';
|
||||
import { getTeams } from './adapter';
|
||||
|
||||
export function getTeamsLookup(tournamentId: number) {
|
||||
@@ -114,10 +120,10 @@ export function getMatchLookupByCourt(swrStagesResponse: SWRResponse) {
|
||||
}
|
||||
|
||||
export function getScheduleData(
|
||||
swrCourtsResponse: SWRResponse,
|
||||
swrCourtsResponse: SWRResponse<CourtsResponse>,
|
||||
matchesByCourtId: any
|
||||
): { court: Court; matches: MatchWithDetails[] }[] {
|
||||
return swrCourtsResponse.data.data.map((court: Court) => ({
|
||||
return (swrCourtsResponse.data?.data || []).map((court: Court) => ({
|
||||
matches: (matchesByCourtId[court.id] || [])
|
||||
.filter((match: MatchWithDetails) => match.start_time != null)
|
||||
.sort((m1: MatchWithDetails, m2: MatchWithDetails) => {
|
||||
|
||||
Reference in New Issue
Block a user