diff --git a/app/actions/edit.js b/app/actions/edit.js index d4611b04f..cf35c7b30 100644 --- a/app/actions/edit.js +++ b/app/actions/edit.js @@ -4,7 +4,8 @@ import { featureToTiles } from '../utils/bbox' import { setNotification } from './notification' import { fetchDataForTile, setSelectedFeatures } from './map' import { getAllRetriable } from '../utils/edit-utils' - +import { getPhotosForFeature } from '../utils/photos' +import { getFeatureInChangeset } from '../services/osm-api' /** * Retries all retriable edits in the current state */ @@ -96,11 +97,27 @@ export function purgeAllEdits () { } export function editUploaded (edit, changesetId) { - return { - type: types.EDIT_UPLOADED, - edit, - changesetId, - timestamp: Number(new Date()) + return async (dispatch, getState) => { + dispatch({ + type: types.EDIT_UPLOADED, + edit, + changesetId, + timestamp: Number(new Date()) + }) + + // check if there are any photos associated with this edit + if (edit.type === 'create') { + const photos = getState().photos.photos + const associatedPhotos = getPhotosForFeature(photos, edit.id) + 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 + } else { + // no photos associated. nothing to do + } + } } } diff --git a/app/services/observe-api.js b/app/services/observe-api.js index 2843ed76a..912ae40d6 100644 --- a/app/services/observe-api.js +++ b/app/services/observe-api.js @@ -70,7 +70,7 @@ export async function uploadPhoto (dispatch, photo) { 'createdAt': new Date(photo.location.timestamp).toISOString(), 'file': photo.base64, 'heading': photo.location.coords.heading >= 0 ? photo.location.coords.heading : null, - 'description': photo.description, + 'description': photo.description || '', 'lon': photo.location.coords.longitude, 'lat': photo.location.coords.latitude, 'osmElement': photo.featureId