Skip to content

Commit

Permalink
Fix issue with match length
Browse files Browse the repository at this point in the history
  • Loading branch information
Spcemarine committed Nov 4, 2022
1 parent 2dd3fc1 commit f85f169
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 65 deletions.
112 changes: 50 additions & 62 deletions src/components/FetchDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import React from 'react';
import { styled } from '@mui/material/styles';
import {
Dialog,
DialogTitle,
Grid,
CircularProgress,
Typography,
DialogContent,
} from '@mui/material';
import { Dialog, DialogTitle, Grid, CircularProgress, Typography, DialogContent } from '@mui/material';
import ToornamentHelper from '../ToornamentHelper';
import CheckIcon from '@mui/icons-material/Check';
import { green } from '@mui/material/colors';
Expand All @@ -19,22 +12,18 @@ const PREFIX = 'FetchDialog';

const classes = {
checkIcon: `${PREFIX}-checkIcon`,
iconContainer: `${PREFIX}-iconContainer`
iconContainer: `${PREFIX}-iconContainer`,
};

const StyledDialog = styled(Dialog)((
{
theme
}
) => ({
const StyledDialog = styled(Dialog)(({ theme }) => ({
[`& .${classes.checkIcon}`]: {
color: green[300],
},

[`& .${classes.iconContainer}`]: {
width: 20,
marginRight: theme.spacing(1),
}
},
}));

interface FetchDialogProps {
Expand Down Expand Up @@ -119,7 +108,7 @@ export default class FetchDialog extends React.Component<FetchDialogProps, Fetch
});

toornamentHelper.getOrganizerMatches(tournamentId, stageId, (matchResults: any[]) => {
const matches = matchResults.map((result) => {
const matches: ScheduleMatch[] = matchResults.map((result) => {
const participants: ScheduleParticipant[] = [];
result.opponents.forEach((opponent: any) => {
if (opponent.participant) {
Expand All @@ -141,62 +130,61 @@ export default class FetchDialog extends React.Component<FetchDialogProps, Fetch
};
});

this.setState({ matches: matches });

const finishMatches = () => {
if (this.state.roundsFinished && this.state.groupsFinished) {
callback(this.state.rounds, this.state.matches, this.state.groups);
} else {
this.setState({ matchesFinished: true });
}
};
this.setState({ matches: matches }, () => {
const finishMatches = () => {
if (this.state.roundsFinished && this.state.groupsFinished) {
callback(this.state.rounds, this.state.matches, this.state.groups);
} else {
this.setState({ matchesFinished: true });
}
};

const getNodes = () => {
toornamentHelper.getBracketNodes(tournamentId, stageId, (results: any[]) => {
results.forEach((result, index) => {
let matchIndex = index;
const matches = this.state.matches;
let match = matches[matchIndex];
const getNodes = () => {
toornamentHelper.getBracketNodes(tournamentId, stageId, (results: any[]) => {
results.forEach((result, index) => {
let matchIndex = index;
const matches = this.state.matches;
let match = matches[matchIndex];

if (match == null || match.id !== result.id) {
matchIndex = matches.findIndex((m) => m.id === result.id);
if (matchIndex < 0) {
return;
if (match == null || match.id !== result.id) {
matchIndex = matches.findIndex((m) => m.id === result.id);
if (matchIndex < 0) {
return;
}
match = matches[matchIndex];
}
match = matches[matchIndex];
}

match.opponents = result.opponents.map((opponent: any) => {
return {
number: opponent.number,
sourceType: opponent.source_type,
sourceNodeId: opponent.source_node_id,
};
match.opponents = result.opponents.map((opponent: any) => {
return {
number: opponent.number,
sourceType: opponent.source_type,
sourceNodeId: opponent.source_node_id,
};
});
matches[matchIndex] = match;
this.setState({ matches: matches, bracketNodeIndex: index + 1 });
});
matches[matchIndex] = match;
this.setState({ matches: matches, bracketNodeIndex: index + 1 });
finishMatches();
});
finishMatches();
});
};
};

const callNext = () => {
if (this.state.matchIndex >= this.state.matches.length) {
getNodes();
return;
}
const callNext = () => {
if (this.state.matchIndex >= this.state.matches.length) {
getNodes();
return;
}

const matchId = this.state.matches[this.state.matchIndex].id;
const callback = (results: any[]) => {
const matches = this.state.matches;
matches[this.state.matchIndex].numberOfGames = results.length;
this.setState({ matches: matches, matchIndex: this.state.matchIndex + 1 });
callNext();
const matchId = this.state.matches[this.state.matchIndex].id;
const callback = (results: any[]) => {
const matches = this.state.matches;
matches[this.state.matchIndex].numberOfGames = results.length;
this.setState({ matches: matches, matchIndex: this.state.matchIndex + 1 }, callNext);
};
toornamentHelper.getOrganizerMatchGames(tournamentId, matchId, callback);
};
toornamentHelper.getOrganizerMatchGames(tournamentId, matchId, callback);
};

callNext();
callNext();
});
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/components/ScheduleStepper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ export default class ScheduleStepper extends React.Component<ScheduleStepperProp
case 1:
this.setState({ fetching: true });
this.props.toornamentHelper.getOrganizerStages(this.state.tournamentId, (results: any[]) => {
console.log(results);
const stages: ScheduleStage[] = results.map((result) => {
return {
id: result.id,
Expand Down Expand Up @@ -182,8 +181,7 @@ export default class ScheduleStepper extends React.Component<ScheduleStepperProp
const round = rounds.find((round) => round.id === match.roundId) || rounds[0];
const continueApplying = () => {
currentIndex++;
this.setState({ applyProgress: currentIndex });
scheduleNext();
this.setState({ applyProgress: currentIndex }, scheduleNext);
};

if (round.scheduledAt === null && match.scheduledAt === null) {
Expand Down

0 comments on commit f85f169

Please sign in to comment.