Merge branch 'fix_match_sorting_in_groups' into 'master'
Fix group stage match sorting See merge request turniere/turniere-frontend!38
This commit is contained in:
commit
9ad65e06bc
|
|
@ -3,6 +3,7 @@ import {Match} from './Match';
|
||||||
import React, {Component} from 'react';
|
import React, {Component} from 'react';
|
||||||
import {getGroup} from '../redux/tournamentApi';
|
import {getGroup} from '../redux/tournamentApi';
|
||||||
import {notify} from 'react-notify-toast';
|
import {notify} from 'react-notify-toast';
|
||||||
|
import {sortMatchesByPositionAscending} from '../utils/sorting';
|
||||||
|
|
||||||
export default class GroupStage extends Component {
|
export default class GroupStage extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
|
|
@ -35,6 +36,7 @@ function ShowMatchesToggleButton(props) {
|
||||||
</Button>);
|
</Button>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class Group extends Component {
|
export class Group extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
@ -62,7 +64,7 @@ export class Group extends Component {
|
||||||
<CardBody>
|
<CardBody>
|
||||||
<h3 className='custom-font'>Gruppe {this.state.number}</h3>
|
<h3 className='custom-font'>Gruppe {this.state.number}</h3>
|
||||||
<Collapse isOpen={this.props.showMatches}>
|
<Collapse isOpen={this.props.showMatches}>
|
||||||
{this.state.matches.map((match => (
|
{this.state.matches.sort(sortMatchesByPositionAscending()).map((match => (
|
||||||
<Match match={match} isSignedIn={this.props.isSignedIn} isOwner={this.props.isOwner}
|
<Match match={match} isSignedIn={this.props.isSignedIn} isOwner={this.props.isOwner}
|
||||||
onChange={this.reload} key={match.id}/>)))}
|
onChange={this.reload} key={match.id}/>)))}
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {MatchTable} from './MatchTable';
|
||||||
|
|
||||||
import styles from './Match.module.css';
|
import styles from './Match.module.css';
|
||||||
|
|
||||||
|
|
||||||
export class Match extends React.Component {
|
export class Match extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import {getRequest} from './backendApi';
|
import {getRequest} from './backendApi';
|
||||||
import {getState} from '../api';
|
import {getState} from '../api';
|
||||||
|
import {sortMatchesByPositionAscending} from '../utils/sorting';
|
||||||
|
|
||||||
export function getTournament(code, successCallback, errorCallback) {
|
export function getTournament(code, successCallback, errorCallback) {
|
||||||
getRequest(getState(), '/tournaments/' + code)
|
getRequest(getState(), '/tournaments/' + code)
|
||||||
|
|
@ -72,15 +73,13 @@ function convertTournament(apiTournament) {
|
||||||
|
|
||||||
function convertPlayoffStage(apiStage) {
|
function convertPlayoffStage(apiStage) {
|
||||||
return {
|
return {
|
||||||
id: apiStage.id, level: apiStage.level, matches: apiStage.matches.sort((a, b) => {
|
id: apiStage.id,
|
||||||
if (a.position < b.position) {
|
level: apiStage.level,
|
||||||
return -1
|
matches: apiStage.matches.sort(
|
||||||
} else if (a.position > b.position) {
|
sortMatchesByPositionAscending()
|
||||||
return 1
|
).map(
|
||||||
} else {
|
match => convertMatch(match, false)
|
||||||
return 0
|
)
|
||||||
}
|
|
||||||
}).map(match => convertMatch(match, false))
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
export function sortMatchesByPositionAscending() {
|
||||||
|
return (a, b) => {
|
||||||
|
if (a.position < b.position) {
|
||||||
|
return -1;
|
||||||
|
} else if (a.position > b.position) {
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue