battleship-front/src/components/Ready.js
Administrator 8b48cddffe dockerfile
2022-08-25 12:26:55 +03:00

49 lines
1.3 KiB
JavaScript

import { Component } from "react";
import request from "../scripts/requests";
class Ready extends Component {
constructor(props) {
super(props);
this.state = {
text: "Расставь корабли чтобы активировать",
disabled: true,
parent: props.parent
}
this.state.parent.ready = this;
this.click = this.click.bind(this);
}
click() {
request("place_ships", {
game_id: this.state.parent.getGameId(),
token: localStorage.getItem('token'),
field: this.state.parent.field.getLine()
}, () => this.setState({
text: "Ждем ответа соперника",
disabled: true
}))
}
update() {
if (!this.props.ok) {
this.setState({
text: "Расставь корабли чтобы активировать",
disabled: true
})
}
else {
this.setState({
text: "Я готов",
disabled: false
})
}
}
render() {
return <button onClick={this.click} className='main' disabled={this.state.disabled}><p>{this.state.text}</p></button>
}
}
export default Ready;