Skip to content

Commit

Permalink
set the photo feature id after feature is uploaded
Browse files Browse the repository at this point in the history
  • Loading branch information
geohacker committed Dec 4, 2019
1 parent 98a49ea commit 520df7d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion __tests__/services/osm-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ test('get feature in changeset', async () => {
fetch.once(xmlData, { status: 200 })
return getFeatureInChangeset(changesetId)
.then(d => {
expect(d).toBe(4319440399)
expect(d).toBe('node/4319440399')
})
})
5 changes: 3 additions & 2 deletions app/actions/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ export function savedPhoto (photo) {
}
}

export function editPhoto (photo, description) {
export function editPhoto (photo, description, featureId) {
return {
type: types.EDIT_PHOTO,
photo,
description
description,
featureId
}
}

Expand Down
5 changes: 4 additions & 1 deletion app/actions/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { fetchDataForTile, setSelectedFeatures } from './map'
import { getAllRetriable } from '../utils/edit-utils'
import { getPhotosForFeature } from '../utils/photos'
import { getFeatureInChangeset } from '../services/osm-api'
import { editPhoto } from '../actions/camera'
/**
* Retries all retriable edits in the current state
*/
Expand Down Expand Up @@ -112,8 +113,10 @@ export function editUploaded (edit, changesetId) {
if (associatedPhotos.length) {
// get feature id
const featureId = await getFeatureInChangeset(changesetId)
console.log('feature id for this photo', featureId)
// fire action to update each photo feature id
for (let photo of associatedPhotos) {
dispatch(editPhoto(photo, photo.description, featureId))
}
} else {
// no photos associated. nothing to do
}
Expand Down
4 changes: 4 additions & 0 deletions app/components/PhotosItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class PhotosItem extends React.PureComponent {
case 'uploaded':
return 'Uploaded'
case 'pending':
if (item.errors.length === 0 && item.featureId.search('observe') > -1) {
return 'Waiting to upload associated feature...'
}

if (item.errors.length === 0) {
return 'Waiting for network...'
}
Expand Down
1 change: 1 addition & 0 deletions app/reducers/camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function (state = initialState, action) {
let photos = [...state.photos]
photos = photos.filter(photo => photo.id !== action.photo.id)
editedPhoto.description = action.description
editedPhoto.featureId = action.featureId
photos.push(editedPhoto)
return {
...state,
Expand Down
2 changes: 1 addition & 1 deletion app/screens/Photos/PhotoDetailScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class PhotoDetailScreen extends React.Component {
onPress: () => {
const editing = !this.state.editing
if (photo.description !== this.state.description) {
editPhoto(photo, this.state.description)
editPhoto(photo, this.state.description, photo.featureId)
}
this.setState({
editing: editing
Expand Down
6 changes: 3 additions & 3 deletions app/services/osm-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ export async function getFeatureInChangeset (changesetId) {
const way = created.filter(c => {
return Object.keys(c) === 'way'
})
featureId = way[0]['$'].id
featureId = `way/${way[0]['$'].id}`
} else {
featureId = created[0]['node'][0]['$'].id
featureId = `node/${created[0]['node'][0]['$'].id}`
}
}
return parseInt(featureId)
return featureId
}

0 comments on commit 520df7d

Please sign in to comment.