From: zharkovstas Date: Sun, 19 May 2019 05:50:04 +0000 (+0500) Subject: Disable ask tip button when no tips left X-Git-Url: https://git.xn--bdkaa.com/?a=commitdiff_plain;h=f5ec8d6ec017106def24759497d36f1aab7651a1;p=where-are-you.py.git Disable ask tip button when no tips left --- diff --git a/app.py b/app.py index 6481ed0..52cf996 100644 --- 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//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//move/') @@ -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//finish//') diff --git a/osm/osm.py b/osm/osm.py index 8c29ed9..adb8a8c 100644 --- a/osm/osm.py +++ b/osm/osm.py @@ -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'] diff --git a/src/Game.js b/src/Game.js index ae37a48..49f4a45 100644 --- a/src/Game.js +++ b/src/Game.js @@ -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 {
-
diff --git a/src/GameController.js b/src/GameController.js index 0546f29..ad44d75 100644 --- a/src/GameController.js +++ b/src/GameController.js @@ -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; }); }