Update group after a match score changes

This commit is contained in:
Felix Hamme 2019-06-15 23:20:30 +02:00
parent 99ca99ea38
commit 8185a7b4b5
3 changed files with 47 additions and 13 deletions

View File

@ -1,6 +1,8 @@
import {Button, Card, CardBody, Col, Collapse, Row, Table} from 'reactstrap';
import {Match} from './Match';
import React, {Component} from 'react';
import {getGroup} from '../redux/tournamentApi';
import {notify} from 'react-notify-toast';
export default class GroupStage extends Component {
constructor(props) {
@ -33,19 +35,42 @@ function ShowMatchesToggleButton(props) {
</Button>);
}
function Group(props) {
return (<Col className='minw-25'>
<Card>
<CardBody>
<h3 className='custom-font'>Gruppe {props.group.id + 1}</h3>
<Collapse isOpen={props.showMatches}>
{props.group.matches.map((match => (
<Match match={match} isSignedIn={props.isSignedIn} isOwner={props.isOwner} key={match.id}/>)))}
</Collapse>
<GroupScoresTable scores={props.group.scores}/>
</CardBody>
</Card>
</Col>);
class Group extends Component {
constructor(props) {
super(props);
this.state = props.group;
this.reload = this.reload.bind(this);
this.onReloadSuccess = this.onReloadSuccess.bind(this);
this.onReloadError = this.onReloadError.bind(this);
}
reload() {
getGroup(this.state.id, this.onReloadSuccess, this.onReloadError);
}
onReloadSuccess(status, updatedGroup) {
this.setState(updatedGroup);
}
onReloadError() {
notify.show('Die Gruppe konnte nicht aktualisiert werden.', 'warning', 2000);
}
render() {
return (<Col className='minw-25'>
<Card>
<CardBody>
<h3 className='custom-font'>Gruppe {this.state.id + 1}</h3>
<Collapse isOpen={this.props.showMatches}>
{this.state.matches.map((match => (
<Match match={match} isSignedIn={this.props.isSignedIn} isOwner={this.props.isOwner}
onChange={this.reload} key={match.id}/>)))}
</Collapse>
<GroupScoresTable scores={this.state.scores}/>
</CardBody>
</Card>
</Col>);
}
}
function GroupScoresTable(props) {

View File

@ -70,6 +70,7 @@ export class Match extends React.Component {
updatedMatch.team1.score = scoreTeam1;
updatedMatch.team2.score = scoreTeam2;
this.setState({match: updatedMatch});
this.props.onChange !== undefined && this.props.onChange();
}
getMatchFinishedMessage() {

View File

@ -9,6 +9,14 @@ export function getTournament(code, successCallback, errorCallback) {
.catch(errorCallback);
}
export function getGroup(groupId, successCallback, errorCallback) {
getRequest(getState(), '/groups/' + groupId)
.then(response => {
successCallback(response.status, convertGroup(response.data));
})
.catch(errorCallback);
}
function convertTournament(apiTournament) {
let groupStage = null;
const playoffStages = [];