]> git.xn--bdkaa.com Git - where-are-you.py.git/commitdiff
Disable ask tip button when no tips left
authorzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 05:50:04 +0000 (10:50 +0500)
committerzharkovstas <zharkovstas@skbkontur.ru>
Sun, 19 May 2019 05:50:32 +0000 (10:50 +0500)
app.py
osm/osm.py
src/Game.js
src/GameController.js

diff --git a/app.py b/app.py
index 6481ed0f5fb0c6fb0ad25edc74bde6c631d14929..52cf996f26b17cf07010f778cdad12b410568b0e 100644 (file)
--- a/app.py
+++ b/app.py
@@ -283,7 +283,9 @@ def get_game(game_id):
 def get_tips(game_id):
     game = games[game_id]
 
-    return {'tips': game.shown_tips}
+    has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0
+
+    return {'tips': game.shown_tips, 'hasMore': has_more}
 
 
 @post('/api/games/<game_id>/ask-tip')
@@ -295,7 +297,10 @@ def get_tip(game_id):
     game = games[game_id]
 
     show_tips(game, 1)
-    return {'tips': game.shown_tips}
+
+    has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0
+
+    return {'tips': game.shown_tips, 'hasMore': has_more}
 
 
 @post('/api/games/<game_id>/move/<direction>')
@@ -319,7 +324,10 @@ def move(game_id, direction):
 
     show_tips(game, 1)
 
-    return {'tips': game.shown_tips}
+    has_more = len([tip for tip in game.tips if tip not in game.shown_tips]) > 0
+
+
+    return {'tips': game.shown_tips, 'hasMore': has_more}
 
 
 @post('/api/games/<game_id>/finish/<latitude>/<longitude>')
index 8c29ed98ee4e4fdb0f31669b0da2952be89710cd..adb8a8c24fcb2f625881e3514a8fb72438d16497 100644 (file)
@@ -34,6 +34,8 @@ def filter_waterways(objects):
 def filter_sightseeings(objects):
     return list(filter(lambda o:
                        o['data']['tag'] != {}
+                       and 'lat' in o['data']
+                       and 'lon' in o['data']
                        and
                        (('tourism' in o['data']['tag']
                          and ('attraction' in o['data']['tag']['tourism']
index ae37a4847c63fee94c439943b4d5d91ee88b6a68..49f4a452611f60ce933878a815e274dc2bb8231b 100644 (file)
@@ -21,7 +21,8 @@ export class Game extends Component {
     this.gameController = new GameController(this.notification);
     this.state = {
       tips: this.gameController.tips(),
-      loading: true
+      loading: true,
+      hasMoreTips: this.gameController.hasMoreTips()
     };
   }
 
@@ -29,6 +30,7 @@ export class Game extends Component {
     this.gameController.createGame().then(() => this.gameController.loadTips()).then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips()),
+        hasMoreTips: this.gameController.hasMoreTips(),
         loading: false,
         inProcess: false
       }, () => {
@@ -49,6 +51,7 @@ export class Game extends Component {
     this.gameController.getMoreTips().then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips()),
+        hasMoreTips: this.gameController.hasMoreTips(),
         inProcess: false
       })
     }).catch(error => {
@@ -69,6 +72,7 @@ export class Game extends Component {
     this.gameController.goNorth().then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips()),
+        hasMoreTips: this.gameController.hasMoreTips(),
         inProcess: false
       })
     }).catch(error => {
@@ -89,6 +93,7 @@ export class Game extends Component {
     this.gameController.goWest().then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips()),
+        hasMoreTips: this.gameController.hasMoreTips(),
         inProcess: false
       })
     }).catch(error => {
@@ -109,6 +114,7 @@ export class Game extends Component {
     this.gameController.goSouth().then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips()),
+        hasMoreTips: this.gameController.hasMoreTips(),
         inProcess: false
       })
     }).catch(error => {
@@ -129,6 +135,7 @@ export class Game extends Component {
       this.gameController.goEast().then(() => {
       this.setState({
         tips: this.handleVarlamov(this.gameController.tips()),
+        hasMoreTips: this.gameController.hasMoreTips(),
         inProcess: false
       })
     }).catch(error => {
@@ -220,7 +227,7 @@ export class Game extends Component {
 
               <div className="Game-controls">
                 <div className="Get-button">
-                  <Button onClick={this.askTip} size="medium" disabled={this.state.inProcess}>
+                  <Button onClick={this.askTip} size="medium" disabled={this.state.inProcess || !this.state.hasMoreTips}>
                     Осмотреться
                   </Button>
                 </div>
index 0546f29fc8bc708d20ff3b411bb02b306dbf0e12..ad44d7538898e82d0902cda2f3ff4c936679d364 100644 (file)
@@ -15,30 +15,35 @@ export class GameController {
   loadTips() {
     return api.get(`/games/${this.gameId}/tips`).then(json => {
       this._tips = json.data.tips;
+      this._hasMoreTips = json.data.hasMore;
     });
   }
 
   goNorth() {
     return api.post(`/games/${this.gameId}/move/north`).then(json => {
       this._tips = json.data.tips;
+      this._hasMoreTips = json.data.hasMore;
     })
   }
 
   goWest() {
     return api.post(`/games/${this.gameId}/move/west`).then(json => {
       this._tips = json.data.tips;
+      this._hasMoreTips = json.data.hasMore;
     })
   }
 
   goSouth() {
     return api.post(`/games/${this.gameId}/move/south`).then(json => {
       this._tips = json.data.tips;
+      this._hasMoreTips = json.data.hasMore;
     })
   }
 
   goEast() {
     return api.post(`/games/${this.gameId}/move/east`).then(json => {
       this._tips = json.data.tips;
+      this._hasMoreTips = json.data.hasMore;
     })
   }
 
@@ -49,6 +54,13 @@ export class GameController {
     return this._tips;
   }
 
+  hasMoreTips() {
+    if(!this._tips) {
+        return true;
+    }
+    return this._hasMoreTips;
+  }
+
   getMoreTips() {
     return api.post(`/games/${this.gameId}/ask-tip`).then(json => {
       if(deepEq(json.data.tips, this.tips())) {
@@ -56,6 +68,7 @@ export class GameController {
         return;
       }
       this._tips = json.data.tips;
+      this._hasMoreTips = json.data.hasMore;
     });
   }