Skip to content

Commit

Permalink
fix(gtfs-plus-actions): fix version fetch after publish
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed May 30, 2017
1 parent e4b9c34 commit 8944deb
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions lib/gtfsplus/actions/gtfsplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import fetch from 'isomorphic-fetch'

import { secureFetch } from '../../common/actions'
import { getConfigProperty } from '../../common/util/config'
import { fetchFeedVersions } from '../../manager/actions/feeds'
// import {stopsAndRoutes, compose} from '../../gtfs/util/graphql'
import { fetchFeedVersions } from '../../manager/actions/versions'
import { getFeedId } from '../../common/util/modules'

// EDIT ACTIVE GTFS+ ACTIONS
Expand Down Expand Up @@ -130,9 +131,7 @@ export function validateGtfsPlusFeed (feedVersionId) {
const url = `/api/manager/secure/gtfsplus/${feedVersionId}/validation`
return dispatch(secureFetch(url))
.then(res => res.json())
.then(validationIssues => {
dispatch(receiveGtfsPlusValidation(validationIssues))
})
.then(validationIssues => dispatch(receiveGtfsPlusValidation(validationIssues)))
}
}

Expand Down Expand Up @@ -215,15 +214,19 @@ export function loadGtfsEntities (tableId, rows, feedSource) {
}
}
}
// TODO: replace multiple fetches with GraphQL
// fetch(compose(stopsAndRoutes(feedId, routesToLoad, stopsToLoad), {feedId, routeId: routesToLoad, stopId: stopsToLoad}))
// .then((response) => response.json())
// .then(results => {
// return dispatch(receivedStopsAndRoutes(results))
// })

if (routesToLoad.length === 0 && stopsToLoad.length === 0) return
const feedId = getFeedId(feedSource)
var loadRoutes = Promise.all(routesToLoad.map(routeId => {
const url = `/api/manager/routes/${routeId}?feed=${feedId}`
return fetch(url)
.then((response) => {
return response.json()
})
.then((response) => response.json())
}))

var loadStops = Promise.all(stopsToLoad.map(stopId => {
Expand All @@ -240,6 +243,14 @@ export function loadGtfsEntities (tableId, rows, feedSource) {
}
}

// const receivedStopsAndRoutes = (results, module) => {
// return {
// type: 'RECEIVED_GTFSPLUS_STOPS_AND_ROUTES',
// results,
// module
// }
// }

// PUBLISH ACTIONS

export function publishingGtfsPlusFeed () {
Expand All @@ -253,9 +264,7 @@ export function publishGtfsPlusFeed (feedVersion) {
dispatch(publishingGtfsPlusFeed())
const url = `/api/manager/secure/gtfsplus/${feedVersion.id}/publish`
return dispatch(secureFetch(url, 'post'))
.then((res) => {
console.log('published done')
return dispatch(fetchFeedVersions(feedVersion.feedSource))
})
.then((res) => res.json())
.then(json => dispatch(fetchFeedVersions(feedVersion.feedSource)))
}
}

0 comments on commit 8944deb

Please sign in to comment.