@@ -4,8 +4,9 @@ import update from 'react-addons-update'
44import clone from 'lodash/cloneDeep'
55import SortDirection from 'react-virtualized/dist/commonjs/Table/SortDirection'
66
7- import { ENTITY } from '../constants '
7+ import { decodeShapePolylines } from '../../common/util/gtfs '
88import { defaultSorter } from '../../common/util/util'
9+ import { ENTITY } from '../constants'
910import { generateNullProps , getTableById , getKeyForId } from '../util/gtfs'
1011import { getMapToGtfsStrategy , entityIsNew } from '../util/objects'
1112import { assignDistancesToPatternStops , constructShapePoints } from '../util/map'
@@ -22,6 +23,11 @@ const getUpdateEntityKeys = component => component === 'trippattern'
2223export const defaultState = {
2324 active : { } ,
2425 lock : { } ,
26+ sort : {
27+ key : 'name' ,
28+ direction : SortDirection . ASC
29+ } ,
30+ status : { } ,
2531 tables : {
2632 agency : [ ] ,
2733 calendar : [ ] ,
@@ -36,11 +42,7 @@ export const defaultState = {
3642 service_id : [ ]
3743 }
3844 } ,
39- sort : {
40- key : 'name' ,
41- direction : SortDirection . ASC
42- } ,
43- status : { }
45+ tripPatterns : null
4446}
4547
4648/* eslint-disable complexity */
@@ -51,6 +53,10 @@ const data = (state: DataState = defaultState, action: Action): DataState => {
5153 return update ( state , { active : { $merge : { feedSourceId} } } )
5254 case 'RECEIVE_BASE_GTFS' : {
5355 const feed = clone ( action . payload . feed )
56+ if ( ! feed ) {
57+ console . warn ( 'Could not fetch base GTFS!' )
58+ return state
59+ }
5460 if ( feed . feed_info . length === 0 ) {
5561 console . warn ( `No feed info found. Adding feed info with null values.` )
5662 feed . feed_info . push ( generateNullProps ( 'feedinfo' ) )
@@ -223,6 +229,11 @@ const data = (state: DataState = defaultState, action: Action): DataState => {
223229 if ( ! tableName ) return state
224230 return update ( state , { tables : { [ tableName ] : { $push : [ entity ] } } } )
225231 }
232+ case 'FETCHING_TRIP_PATTERNS' : {
233+ // Set value to an empty array to prevent the user from accidentally
234+ // triggering multiple fetches.
235+ return update ( state , { tripPatterns : { $set : [ ] } } )
236+ }
226237 case 'RECEIVE_GTFS_ENTITIES' : {
227238 let activePattern
228239 const { data, editor, component} = action . payload
@@ -235,17 +246,7 @@ const data = (state: DataState = defaultState, action: Action): DataState => {
235246 // Handle trip patterns to be drawn as overlay layer in editor
236247 return update ( state , {
237248 tripPatterns : { $set :
238- data . feed . patterns . map ( pattern => {
239- return {
240- id : pattern . id ,
241- name : pattern . name ,
242- route_id : pattern . route_id ,
243- latLngs : pattern . shape_points
244- ? ( pattern . shape_points . map ( sp =>
245- ( { lon : sp . shape_pt_lon , lat : sp . shape_pt_lat } ) ) )
246- : null
247- }
248- } )
249+ data . feed . shapes_as_polylines . map ( decodeShapePolylines )
249250 }
250251 } )
251252 }
0 commit comments