Skip to content

Commit

Permalink
Merge pull request #71 from graasp/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
juancarlosfarah authored May 6, 2019
2 parents 88b244b + 611f988 commit f9cd556
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
45 changes: 24 additions & 21 deletions src/actions/user/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@ import {
} from '../../config/messages';

const getGeolocation = async () => async dispatch => {
try {
const geolocation = await getCurrentPosition();
const payload = {
coords: {
accuracy: geolocation.coords.accuracy,
altitude: geolocation.coords.altitude,
altitudeAccuracy: geolocation.coords.altitudeAccuracy,
heading: geolocation.coords.heading,
latitude: geolocation.coords.latitude,
longitude: geolocation.coords.longitude,
speed: geolocation.coords.speed,
},
timestamp: geolocation.timestamp,
};
dispatch({
type: GET_GEOLOCATION_SUCCEEDED,
payload,
});
} catch (e) {
console.error(e);
toastr.error(ERROR_MESSAGE_HEADER, ERROR_GETTING_GEOLOCATION);
// only fetch location if online
if (window.navigator.onLine) {
try {
const geolocation = await getCurrentPosition();
const payload = {
coords: {
accuracy: geolocation.coords.accuracy,
altitude: geolocation.coords.altitude,
altitudeAccuracy: geolocation.coords.altitudeAccuracy,
heading: geolocation.coords.heading,
latitude: geolocation.coords.latitude,
longitude: geolocation.coords.longitude,
speed: geolocation.coords.speed,
},
timestamp: geolocation.timestamp,
};
dispatch({
type: GET_GEOLOCATION_SUCCEEDED,
payload,
});
} catch (e) {
console.error(e);
toastr.error(ERROR_MESSAGE_HEADER, ERROR_GETTING_GEOLOCATION);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/components/LoadSpace.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class LoadSpace extends Component {
};

handleFileLocation = event => {
const fileLocation = event.target.value;
const fileLocation = event.target ? event.target.value : event;
this.setState({ fileLocation });
};

Expand Down
7 changes: 7 additions & 0 deletions src/components/SpacesNearby.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ class SpacesNearby extends Component {
this.getSpacesNearby();
}

componentDidUpdate({ geolocation: prevGeolocation }) {
const { geolocation } = this.props;
if (!geolocation.equals(prevGeolocation)) {
this.getSpacesNearby();
}
}

getSpacesNearby = () => {
const { dispatchGetSpacesNearby, geolocation } = this.props;
if (!geolocation.isEmpty()) {
Expand Down

0 comments on commit f9cd556

Please sign in to comment.