From 3a53e81a14ca768df1a18dcb4234f5e7fc930771 Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Thu, 30 Mar 2017 11:21:19 +0200 Subject: [PATCH] Fix ui gateway location race-condition. --- docs/changelog.md | 7 +++++++ mkdocs.yml | 2 +- ui/src/components/GatewayForm.js | 22 +++++++++++----------- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/docs/changelog.md b/docs/changelog.md index 165762faa..b906619b3 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 0.7.2 + +**Bugfixes:** + +* Fix race-condition between fetching the gateway details and getting the + current location if the gateway location is not yet set (UI). + ## 0.7.1 **Features & changes:** diff --git a/mkdocs.yml b/mkdocs.yml index 6c51e41bb..acfd8e5f1 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -15,7 +15,7 @@ pages: - changelog.md extra: - version: '0.7.1' + version: '0.7.2' github: download_release: true diff --git a/ui/src/components/GatewayForm.js b/ui/src/components/GatewayForm.js index 289cf6751..c4985a813 100644 --- a/ui/src/components/GatewayForm.js +++ b/ui/src/components/GatewayForm.js @@ -54,20 +54,20 @@ class GatewayForm extends Component { gateway: this.props.gateway, }); - if (typeof(this.state.gateway.latitude) === "undefined" || typeof(this.state.gateway.longitude) === "undefined" || this.state.gateway.latitude === 0 || this.state.gateway.longitude === 0) { - this.setToCurrentPosition(); - } + this.setToCurrentPosition(false); } - setToCurrentPosition() { + setToCurrentPosition(overwrite) { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition((position) => { - let gateway = this.state.gateway; - gateway.latitude = position.coords.latitude; - gateway.longitude = position.coords.longitude; - this.setState({ - gateway: gateway, - }); + if (overwrite === true || typeof(this.state.gateway.latitude) === "undefined" || typeof(this.state.gateway.longitude) === "undefined" || this.state.gateway.latitude === 0 || this.state.gateway.longitude === 0) { + let gateway = this.state.gateway; + gateway.latitude = position.coords.latitude; + gateway.longitude = position.coords.longitude; + this.setState({ + gateway: gateway, + }); + } }); } } @@ -85,7 +85,7 @@ class GatewayForm extends Component { handleSetToCurrentPosition(e) { e.preventDefault(); - this.setToCurrentPosition(); + this.setToCurrentPosition(true); } render() {