diff --git a/ReactNativeClient/src/components/screens/note.js b/ReactNativeClient/src/components/screens/note.js index 187b0654d..517efbaeb 100644 --- a/ReactNativeClient/src/components/screens/note.js +++ b/ReactNativeClient/src/components/screens/note.js @@ -43,7 +43,11 @@ class NoteScreenComponent extends React.Component { } saveNoteButton_press = () => { - Note.save(this.state.note); + let isNew = !this.state.note.id; + Note.save(this.state.note).then((note) => { + Log.info('NOTE', note); + if (isNew) Note.updateGeolocation(note.id); + }); } render() { diff --git a/ReactNativeClient/src/models/note.js b/ReactNativeClient/src/models/note.js index b8db02c8a..fb7468349 100644 --- a/ReactNativeClient/src/models/note.js +++ b/ReactNativeClient/src/models/note.js @@ -36,38 +36,31 @@ class Note extends BaseModel { }); } - static byFolderId() { + static updateGeolocation(noteId) { + Log.info('Updating lat/long of note ' + noteId); + let geoData = null; + return Geolocation.currentPosition().then((data) => { + Log.info('Got lat/long'); + geoData = data; + return Note.load(noteId); + }).then((note) => { + if (!note) return; // Race condition note - has been deleted in the meantime + note.longitude = geoData.coords.longitude; + note.latitude = geoData.coords.latitude; + note.altitude = geoData.coords.altitude; + return Note.save(note); + }).catch((error) => { + Log.info('Cannot get location:', error); + }); } static save(o, options = null) { - if (!options) options = {}; - if (!('updateLatLong' in options)) options.updateLatLong = true; - return super.save(o, options).then((note) => { this.dispatch({ type: 'NOTES_UPDATE_ONE', note: note, }); - - if (options.updateLatLong && !note.latitude && !note.longitude) { - Log.info('Updating lat/long of note...'); - let geoData = null; - Geolocation.currentPosition().then((data) => { - Log.info('Got lat/long'); - geoData = data; - return Note.load(note.id); - }).then((note) => { - if (!note) return; // Has been deleted in the meantime - note.longitude = geoData.coords.longitude; - note.latitude = geoData.coords.latitude; - note.altitude = geoData.coords.altitude; - Note.save(note, { updateLatLong: false }); - }).catch((error) => { - Log.info('Cannot get location:', error); - }); - } - return note; }); }