49 lines
1.3 KiB
JavaScript
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; |