This commit is contained in:
Administrator 2022-08-25 20:23:46 +03:00
parent 9983f7b212
commit 3d71f5dee6
3 changed files with 23 additions and 26 deletions

View File

@ -1,5 +1,4 @@
import { Component } from "react";
import request from "../scripts/requests";
class Ready extends Component {
@ -10,19 +9,6 @@ class Ready extends Component {
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() {
@ -41,7 +27,7 @@ class Ready extends Component {
}
render() {
return <button onClick={this.click} className='main' disabled={this.state.disabled}><p>{this.state.text}</p></button>
return <button onClick={this.props.onClick} className='main' disabled={this.props.disabled}><p>{this.props.text}</p></button>
}
}

View File

@ -18,7 +18,9 @@ class NewGame extends Component {
constructor(props) {
super(props);
this.state = {
ok: false
ok: false,
readyText: "Заполни поле чтобы начать",
readyDisabled: true
}
this.queryParams = new URLSearchParams(window.location.search);
}
@ -26,22 +28,31 @@ class NewGame extends Component {
update() {
const line = this.field.getLine();
request("check_field_correct", {field: line}, (response) => {
this.setState({ok: response.correct});
if (response.correct) {
this.ready.setState({
text: "Я готов",
disabled: false
this.setState({
readyText: "Я готов",
readyDisabled: false
})
} else {
this.ready.setState({
text: "Расставь корабли чтобы активировать",
disabled: true
this.setState({
readyText: "Заполни поле чтобы начать",
readyDisabled: true
})
}
this.ready.setState({ok: this.state.ok});
});
}
clickReady() {
request("place_ships", {
game_id: this.getGameId(),
token: localStorage.getItem('token'),
field: this.field.getLine()
}, (response) => this.setState({
readyText: "Ждем ответа соперника",
readyDisabled: true
}))
}
render() {
return (
<div>
@ -67,7 +78,7 @@ class NewGame extends Component {
<p>Ссылка для подключения</p>
<input className='borders' value={host + "connect?token=" + this.getToken()} />
</center>
<Ready ok={this.state.ok} parent={this} />
<Ready onClick={() => this.clickReady()} text={this.state.readyText} disabled={this.state.readyDisabled} />
</div>
);
}

View File

@ -1,4 +1,4 @@
export const host = "http://battleship.develop.sprinthub.ru/"
export const host = "http://127.0.0.1:8000/"
function request(method, body, callback) {