diff --git a/lib/editor/actions/editor.js b/lib/editor/actions/editor.js index e650f58b7..3b05683a9 100644 --- a/lib/editor/actions/editor.js +++ b/lib/editor/actions/editor.js @@ -197,7 +197,7 @@ export function newGtfsEntities (feedSourceId, component, propsArray, save) { } } -export function newGtfsEntity (feedSourceId, component, props, save) { +export function newGtfsEntity (feedSourceId, component, props, save, refetch = true) { return function (dispatch, getState) { if (!props) { props = generateProps(component, getState().editor) @@ -208,7 +208,7 @@ export function newGtfsEntity (feedSourceId, component, props, save) { ...props } if (save) { - return dispatch(saveActiveGtfsEntity(component, props)) + return dispatch(saveActiveGtfsEntity(component, props, refetch)) } else { dispatch(createGtfsEntity(feedSourceId, component, props)) if (props && 'routeId' in props) { @@ -300,30 +300,36 @@ export function fetchBaseGtfs ({namespace, component, newId, activeEntityId, fee } ` // TODO: fetch patterns / subcomponent in nested query? - return dispatch(lockEditorFeedSource(feedSourceId)) - .then(lockSuccess => { - if (!lockSuccess) { - console.warn('No lock on editor. Canceling feed fetch') - dispatch(setEditorCheckIn({feedId: null, sessionId: null, timer: null, timestamp: null})) - browserHistory.push(`/feed/${feedSourceId}/edit`) - return - } - dispatch(fetchingBaseGtfs({namespace})) - if (!namespace) { - console.error('Cannot fetch GTFS for undefined or null namespace') - dispatch(showEditorModal()) - return - } - return dispatch(fetchGraphQL({query, variables: {namespace}})) - .then(res => res.json()) - .then(data => dispatch(receiveBaseGtfs({...data}))) - // FIXME? Setting active entity is currently done after fetching base GTFS - // (in a separate action). Maybe we want to combine that step here. - // .then(() => { - // console.log('setting active after fetch', component, newId) - // dispatch(dispatch(setActiveGtfsEntity(feedSourceId, component, newId, subComponent, subEntityId, subSubComponent, activeSubSubEntity))) - // }) - // .catch(err => console.log(err)) - }) + if (!getState().editor.data.lock.sessionId) { + return dispatch(lockEditorFeedSource(feedSourceId)) + .then(lockSuccess => { + if (!lockSuccess) { + console.warn('No lock on editor. Canceling feed fetch') + dispatch(setEditorCheckIn({feedId: null, sessionId: null, timer: null, timestamp: null})) + browserHistory.push(`/feed/${feedSourceId}/edit`) + return + } + dispatch(fetchingBaseGtfs({namespace})) + if (!namespace) { + console.error('Cannot fetch GTFS for undefined or null namespace') + dispatch(showEditorModal()) + return + } + return dispatch(fetchGraphQL({query, variables: {namespace}})) + .then(res => res.json()) + .then(data => dispatch(receiveBaseGtfs({...data}))) + }) + } else { + // If there is already a session lock, skip trying to create another. + dispatch(fetchingBaseGtfs({namespace})) + if (!namespace) { + console.error('Cannot fetch GTFS for undefined or null namespace') + dispatch(showEditorModal()) + return + } + return dispatch(fetchGraphQL({query, variables: {namespace}})) + .then(res => res.json()) + .then(data => dispatch(receiveBaseGtfs({...data}))) + } } }