Skip to content

Commit

Permalink
Fix ui gateway location race-condition.
Browse files Browse the repository at this point in the history
  • Loading branch information
brocaar committed Mar 30, 2017
1 parent 154f738 commit 3a53e81
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -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:**
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pages:
- changelog.md

extra:
version: '0.7.1'
version: '0.7.2'
github:
download_release: true

Expand Down
22 changes: 11 additions & 11 deletions ui/src/components/GatewayForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
}
});
}
}
Expand All @@ -85,7 +85,7 @@ class GatewayForm extends Component {

handleSetToCurrentPosition(e) {
e.preventDefault();
this.setToCurrentPosition();
this.setToCurrentPosition(true);
}

render() {
Expand Down

0 comments on commit 3a53e81

Please sign in to comment.