From a3fa29804e3a113a539d9fe88994efca3b898e15 Mon Sep 17 00:00:00 2001 From: Sebastian Ovide Date: Mon, 19 Nov 2018 15:46:08 +0000 Subject: [PATCH] fixed geolocation not updating (#114) --- src/App.js | 34 ++++++------- src/components/PhotoPage.js | 94 +++++++++++++++-------------------- src/components/PhotoPage.scss | 6 ++- 3 files changed, 60 insertions(+), 74 deletions(-) diff --git a/src/App.js b/src/App.js index df5579f5..04c4eed9 100644 --- a/src/App.js +++ b/src/App.js @@ -12,18 +12,18 @@ class App extends Component { this.state = { renderPage: () => (), file: null, - location: {}, - isSignedIn: undefined, + location: null, + isSignedIn: null, photosToModerate: [] }; this.geoid = null; } openAnonymousPage = () => { - this.setState({ renderPage: () => () }); + this.setState({ renderPage: () => () }); }; - closePage = () => { + openLandingPage = () => { this.setState({ renderPage: () => ( { - this.setState({ renderPage: () => () }); + this.setState({ renderPage: () => () }); }; openEverybodyPage = () => { - this.setState({ renderPage: () => () }); + this.setState({ renderPage: () => () }); }; openModeratorPage = () => { - this.setState({ renderPage: () => () }); + this.setState({ renderPage: () => () }); }; openPhotoPage = (file) => { this.setState({ - renderPage: () => (), + renderPage: () => (), file }); }; openMap = () => { - this.setState({ renderPage: () => () }); + this.setState({ renderPage: () => () }); }; - getLocation() { + setLocationWatcher() { if (navigator && navigator.geolocation) { this.geoid = navigator.geolocation.watchPosition(position => { const location = { latitude: position.coords.latitude, longitude: position.coords.longitude }; + this.setState({ location }); - this.closePage(); - }, error => { console.log('Error: ', error.message); - this.closePage(); - }, { - enableHighAccuracy: true, - timeout: 3000 }); } } @@ -98,7 +93,9 @@ class App extends Component { this.setState({isSignedIn: user}); }); - this.getLocation(); + this.setLocationWatcher(); + + this.openLandingPage(); } async componentWillUnmount() { @@ -109,8 +106,7 @@ class App extends Component { await this.unregisterPhotosToModerate(); await config.dbModule.disconnect(); - if(navigator.geolocation) navigator.geolocation.clearWatch(this.geoid); - + if(this.geoid && navigator.geolocation) navigator.geolocation.clearWatch(this.geoid); } render() { diff --git a/src/components/PhotoPage.js b/src/components/PhotoPage.js index bed658ba..c83b7fcb 100644 --- a/src/components/PhotoPage.js +++ b/src/components/PhotoPage.js @@ -5,7 +5,9 @@ import Dialog from '@material-ui/core/Dialog'; import DialogActions from '@material-ui/core/DialogActions'; import DialogContent from '@material-ui/core/DialogContent'; import DialogContentText from '@material-ui/core/DialogContentText'; -import Loading from './Loading'; +import CircularProgress from '@material-ui/core/CircularProgress'; + +// import Loading from './Loading'; import backButton from '../images/left-arrow.svg'; import config from '../custom/config'; import './PhotoPage.scss'; @@ -16,65 +18,61 @@ class PhotoPage extends Component { this.state = { imgSrc: '', open: false, - opendialogtext: false, message: '', value: '', sending: false - };; + }; this.base64 = null; + this.dialogCloseCallback = null; } handleChange = (event) => { this.setState({ value: event.target.value }); } - openDialog = (message) => { + openDialog = (message, fn) => { this.setState({ sending: false, open: true, message }); + + this.dialogCloseCallback = fn; } closeDialog = () => { - this.setState({ open: false }); - if (this.state.message === 'Failed to upload. Please try again!') { - this.loadImage(); - } else { - this.closePage(); - } + this.dialogCloseCallback ? this.dialogCloseCallback() : this.setState({ open: false }); } - openDialogText = () => { - this.setState({ opendialogtext: true }); - } + sendFile = async () => { + if (!this.props.location) { + this.openDialog("Could not get the location yet. You won't be able to upload an image."); + } else { - closeDialogText = () => { - this.setState({ opendialogtext: false }); - } + let data = {}; + const text = this.state.value; + const { location } = this.props; + data.base64 = this.base64; + if (text !== '') { + data['text'] = text; + if (location) { + data['latitude'] = location.latitude; + data['longitude'] = location.longitude; + } + this.setState({ sending: true }); + try { + const res = await config.uploadPhoto(data); + console.log(res); + this.openDialog("Photo was uploaded successfully", this.closePage); - sendFile = async () => { - let data = {} - const text = this.state.value; - const { location } = this.props; - data.base64 = this.base64; - if (text !== '') { - data['text'] = text; - if (location) { - data['latitude'] = location.latitude; - data['longitude'] = location.longitude; - } - this.setState({ sending: true }); - try { - const res = await config.uploadPhoto(data); - console.log(res); - this.openDialog("Photo was uploaded successfully"); - } catch (e) { - this.openDialog(e.message || e); + } catch (e) { + this.openDialog(e.message || e); + } + } else { + this.openDialog("Please enter some text"); } - } else { - this.openDialogText(); + } } @@ -120,10 +118,7 @@ class PhotoPage extends Component { render() { return ( - this.state.sending ? - - : -
+
- + + - - Please enter some text + + Be patient ;) + - - - +
); } diff --git a/src/components/PhotoPage.scss b/src/components/PhotoPage.scss index c8115ff6..044e291c 100644 --- a/src/components/PhotoPage.scss +++ b/src/components/PhotoPage.scss @@ -16,7 +16,6 @@ .buttonback { height:25px } - } .entertext { @@ -56,5 +55,8 @@ } +} -}; +.progress { + color: $color2 !important; +}