From 229def3d76612f2f99bf8836ce6e972f6348cd42 Mon Sep 17 00:00:00 2001 From: zharkovstas Date: Sun, 19 May 2019 10:04:12 +0500 Subject: [PATCH] Disable buttons when is loading --- src/Game.js | 60 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/src/Game.js b/src/Game.js index df7f4da..6039bdb 100644 --- a/src/Game.js +++ b/src/Game.js @@ -29,7 +29,8 @@ export class Game extends Component { this.gameController.createGame().then(() => this.gameController.loadTips()).then(() => { this.setState({ tips: this.handleVarlamov(this.gameController.tips()), - loading: false + loading: false, + inProcess: false }, () => { createMap('map', this.onMapClick); }) @@ -42,11 +43,18 @@ export class Game extends Component { } askTip = () => { + this.setState({ + inProcess: true + }); this.gameController.getMoreTips().then(() => { this.setState({ - tips: this.handleVarlamov(this.gameController.tips()) + tips: this.handleVarlamov(this.gameController.tips()), + inProcess: false }) }).catch(error => { + this.setState({ + inProcess: false + }); this.notification.show( 'Что-то сломалось, зовите разраба', error && JSON.stringify(error) @@ -55,54 +63,82 @@ export class Game extends Component { }; moveNorth = () => { + this.setState({ + inProcess: true + }); this.gameController.goNorth().then(() => { this.setState({ - tips: this.handleVarlamov(this.gameController.tips()) + tips: this.handleVarlamov(this.gameController.tips()), + inProcess: false }) }).catch(error => { this.notification.show( 'Что-то сломалось, зовите разраба', error && JSON.stringify(error) ); + this.setState({ + inProcess: false + }); }); }; moveWest = () => { + this.setState({ + inProcess: true + }); this.gameController.goWest().then(() => { this.setState({ - tips: this.handleVarlamov(this.gameController.tips()) + tips: this.handleVarlamov(this.gameController.tips()), + inProcess: false }) }).catch(error => { this.notification.show( 'Что-то сломалось, зовите разраба', error && JSON.stringify(error) ); + this.setState({ + inProcess: false + }); }); }; moveSouth = () => { + this.setState({ + inProcess: true + }); this.gameController.goSouth().then(() => { this.setState({ - tips: this.handleVarlamov(this.gameController.tips()) + tips: this.handleVarlamov(this.gameController.tips()), + inProcess: false }) }).catch(error => { this.notification.show( 'Что-то сломалось, зовите разраба', error && JSON.stringify(error) ); + this.setState({ + inProcess: false + }); }); }; moveEast = () => { - this.gameController.goEast().then(() => { this.setState({ - tips: this.handleVarlamov(this.gameController.tips()) + inProcess: true + }); + this.gameController.goEast().then(() => { + this.setState({ + tips: this.handleVarlamov(this.gameController.tips()), + inProcess: false }) }).catch(error => { this.notification.show( 'Что-то сломалось, зовите разраба', error && JSON.stringify(error) ); + this.setState({ + inProcess: false + }); }); }; @@ -161,27 +197,27 @@ export class Game extends Component {
-
-
-
-
-
-- 2.50.1