Attacks are now pending
This commit is contained in:
@@ -218,7 +218,7 @@ class Profile extends React.Component {
|
||||
<div className='row'>
|
||||
<p className='col'>Recruits:</p>
|
||||
<p className='col'>{this.state.recruits}</p>
|
||||
<AttackButton className='col' style={{flex: '2 1 1.5%'}} setWarning={this.setWarning.bind(this)} attacker={this.props.username} defender={this.state.username} />
|
||||
<AttackButton className='col' style={{flex: '2 1 1.5%'}} setWarning={this.setWarning.bind(this)} attacker={this.props.username} defender={this.state.username} token={this.props.token} />
|
||||
</div>
|
||||
|
||||
<div className='row'>
|
||||
|
||||
@@ -8,14 +8,22 @@ class AttackButton extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
//
|
||||
message: ''
|
||||
};
|
||||
|
||||
this.sendAttackingStatusRequest();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<button className={this.props.className} style={this.props.style} onClick={this.sendAttackRequest.bind(this)} disabled={this.props.disabled}>Attack</button>
|
||||
);
|
||||
if (this.state.message !== '') {
|
||||
return (
|
||||
<p>{this.state.message}</p>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<button className={this.props.className} style={this.props.style} onClick={this.sendAttackRequest.bind(this)} disabled={this.props.disabled}>Attack</button>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sendAttackRequest() {
|
||||
@@ -26,7 +34,7 @@ class AttackButton extends React.Component {
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
//DO NOTHING
|
||||
this.setState({message: xhr.responseText});
|
||||
} else if (xhr.status === 400) {
|
||||
if (this.props.setWarning) {
|
||||
this.props.setWarning(xhr.responseText);
|
||||
@@ -38,7 +46,8 @@ class AttackButton extends React.Component {
|
||||
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||
xhr.send(JSON.stringify({
|
||||
attacker: this.props.attacker,
|
||||
defender: this.props.defender
|
||||
defender: this.props.defender,
|
||||
token: this.props.token
|
||||
}));
|
||||
|
||||
if (this.props.onClick) {
|
||||
@@ -47,6 +56,26 @@ class AttackButton extends React.Component {
|
||||
|
||||
this.props.setDisabled(true);
|
||||
}
|
||||
|
||||
sendAttackingStatusRequest() {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open('POST', '/attackstatusrequest', true);
|
||||
|
||||
xhr.onreadystatechange = () => {
|
||||
if (xhr.readyState === 4) {
|
||||
if (xhr.status === 200) {
|
||||
if (xhr.responseText === 'attacking') {
|
||||
this.props.setDisabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||
xhr.send(JSON.stringify({
|
||||
username: this.props.attacker
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
AttackButton.propTypes = {
|
||||
@@ -56,6 +85,7 @@ AttackButton.propTypes = {
|
||||
setWarning: PropTypes.func,
|
||||
attacker: PropTypes.string.isRequired,
|
||||
defender: PropTypes.string.isRequired,
|
||||
token: PropTypes.number.isRequired,
|
||||
|
||||
disabled: PropTypes.bool.isRequired,
|
||||
setDisabled: PropTypes.func.isRequired
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { SET_ATTACK_DISABLED } from '../actions/combat.js';
|
||||
|
||||
const initialStore = {
|
||||
attackDisabled: true
|
||||
attackDisabled: false
|
||||
};
|
||||
|
||||
export function combatReducer(store = initialStore, action) {
|
||||
|
||||
Reference in New Issue
Block a user