Implement starting a match, make backend calls
This commit is contained in:
parent
bcb7381fe7
commit
7848d3d81d
25
js/api.js
25
js/api.js
|
|
@ -221,6 +221,19 @@ const reducerTournamentinfo = (state = defaultStateTournamentinfo, action) => {
|
||||||
return Object.assign({}, state, {});
|
return Object.assign({}, state, {});
|
||||||
case actionTypesTournamentinfo.REHYDRATE:
|
case actionTypesTournamentinfo.REHYDRATE:
|
||||||
|
|
||||||
|
return Object.assign({}, state, {});
|
||||||
|
case actionTypesTournamentinfo.START_MATCH:
|
||||||
|
patchRequest(action.state, '/matches/' + action.parameters.matchId, {
|
||||||
|
state: 'in_progress'
|
||||||
|
}).then(resp => {
|
||||||
|
storeOptionalToken(resp);
|
||||||
|
action.parameters.successCallback();
|
||||||
|
}).catch(error => {
|
||||||
|
if (error.response) {
|
||||||
|
storeOptionalToken(error.response);
|
||||||
|
}
|
||||||
|
action.parameters.errorCallback();
|
||||||
|
});
|
||||||
return Object.assign({}, state, {});
|
return Object.assign({}, state, {});
|
||||||
case actionTypesTournamentinfo.CLEAR:
|
case actionTypesTournamentinfo.CLEAR:
|
||||||
|
|
||||||
|
|
@ -364,6 +377,18 @@ export function updateTeamName(team, successCB, errorCB) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function startMatch(matchId, successCallback, errorCallback) {
|
||||||
|
__store.dispatch({
|
||||||
|
type: actionTypesTournamentinfo.START_MATCH,
|
||||||
|
parameters: {
|
||||||
|
matchId: matchId,
|
||||||
|
successCallback: successCallback,
|
||||||
|
errorCallback: errorCallback
|
||||||
|
},
|
||||||
|
state: __store.getState()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function getState() {
|
export function getState() {
|
||||||
return __store.getState();
|
return __store.getState();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,15 +12,21 @@ import {
|
||||||
Table
|
Table
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import {startMatch} from '../api';
|
||||||
|
import {notify} from 'react-notify-toast';
|
||||||
|
|
||||||
|
|
||||||
export class Match extends React.Component {
|
export class Match extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
modal: false
|
modal: false,
|
||||||
|
matchState: this.props.match.state
|
||||||
};
|
};
|
||||||
this.toggleModal = this.toggleModal.bind(this);
|
this.toggleModal = this.toggleModal.bind(this);
|
||||||
|
this.startMatch = this.startMatch.bind(this);
|
||||||
|
this.onStartMatchSuccess = this.onStartMatchSuccess.bind(this);
|
||||||
|
this.onStartMatchError = this.onStartMatchError.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleModal() {
|
toggleModal() {
|
||||||
|
|
@ -31,12 +37,26 @@ export class Match extends React.Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startMatch() {
|
||||||
|
startMatch(this.props.match.id, this.onStartMatchSuccess, this.onStartMatchError);
|
||||||
|
}
|
||||||
|
|
||||||
|
onStartMatchSuccess() {
|
||||||
|
this.setState({matchState: 'in_progress'});
|
||||||
|
this.toggleModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
onStartMatchError() {
|
||||||
|
this.toggleModal();
|
||||||
|
notify.show('Das Match konnte nicht gestartet werden.', 'error', 3000);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let cardClass;
|
let cardClass;
|
||||||
let smallMessage;
|
let smallMessage;
|
||||||
let borderClass;
|
let borderClass;
|
||||||
// possible states: single_team not_ready not_started in_progress team1_won team2_won undecided
|
// possible states: single_team not_ready not_started in_progress team1_won team2_won undecided
|
||||||
switch (this.props.match.state) {
|
switch (this.state.matchState) {
|
||||||
case 'in_progress':
|
case 'in_progress':
|
||||||
cardClass = 'table-warning';
|
cardClass = 'table-warning';
|
||||||
borderClass = 'border-warning';
|
borderClass = 'border-warning';
|
||||||
|
|
@ -76,7 +96,8 @@ export class Match extends React.Component {
|
||||||
</CardBody>
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
<small className='text-muted'>{smallMessage}</small>
|
<small className='text-muted'>{smallMessage}</small>
|
||||||
<MatchModal title='Match' isOpen={this.state.modal} toggle={this.toggleModal} match={this.props.match}/>
|
<MatchModal title='Match' isOpen={this.state.modal} toggle={this.toggleModal} match={this.props.match}
|
||||||
|
startMatch={this.startMatch}/>
|
||||||
</div>);
|
</div>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -104,7 +125,7 @@ function MatchModal(props) {
|
||||||
break;
|
break;
|
||||||
case 'not_started':
|
case 'not_started':
|
||||||
title = 'Spiel kann gestartet werden';
|
title = 'Spiel kann gestartet werden';
|
||||||
actionButton = <Button color='primary' onClick={props.toggle}>Spiel starten</Button>;
|
actionButton = <Button color='primary' onClick={props.startMatch}>Spiel starten</Button>;
|
||||||
break;
|
break;
|
||||||
case 'undecided':
|
case 'undecided':
|
||||||
title = 'Spiel beendet';
|
title = 'Spiel beendet';
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ export const actionTypesTournamentinfo = {
|
||||||
'MODIFY_TOURNAMENT_SUCCESS': 'MODIFY_TOURNAMENT_SUCCESS',
|
'MODIFY_TOURNAMENT_SUCCESS': 'MODIFY_TOURNAMENT_SUCCESS',
|
||||||
'MODIFY_TOURNAMENT_ERROR': 'MODIFY_TOURNAMENT_ERROR',
|
'MODIFY_TOURNAMENT_ERROR': 'MODIFY_TOURNAMENT_ERROR',
|
||||||
|
|
||||||
|
'START_MATCH': 'START_MATCH',
|
||||||
|
|
||||||
'REHYDRATE': 'TOURNAMENTINFO_REHYDRATE',
|
'REHYDRATE': 'TOURNAMENTINFO_REHYDRATE',
|
||||||
'CLEAR': 'TOURNAMENTINFO_CLEAR'
|
'CLEAR': 'TOURNAMENTINFO_CLEAR'
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue