@@ -5,6 +5,7 @@ import fetch, {fetchMultiple} from '@conveyal/woonerf/fetch'
5
5
import { retrieveConfig , storeConfig } from '../config'
6
6
import { ACCESSIBILITY_IS_LOADING , ACCESSIBILITY_IS_EMPTY } from '../constants'
7
7
import type { LonLat } from '../types'
8
+ import cacheURL from '../utils/cache-url'
8
9
import coordinateToPoint , { pointToCoordinate } from '../utils/coordinate-to-point'
9
10
import { parsePathsData , warnForInvalidPaths } from '../utils/parse-paths-data'
10
11
import { parseTimesData } from '../utils/parse-times-data'
@@ -84,7 +85,7 @@ export const initialize = (startCoordinate?: LonLat) => (dispatch, getState) =>
84
85
}
85
86
86
87
dispatch ( fetch ( {
87
- url : 'config.json' ,
88
+ url : cacheURL ( 'config.json' ) ,
88
89
next : response => {
89
90
const c = response . value
90
91
storeConfig ( c )
@@ -131,7 +132,8 @@ export const loadDataset = (
131
132
dispatch ( fetchMultiple ( {
132
133
fetches : networks . reduce ( ( urls , n ) => [
133
134
...urls ,
134
- { url : `${ n . url } /request.json` } , { url : `${ n . url } /transitive.json` }
135
+ { url : cacheURL ( `${ n . url } /request.json` ) } ,
136
+ { url : cacheURL ( `${ n . url } /transitive.json` ) }
135
137
] , [ ] ) ,
136
138
next : responses => {
137
139
let offset = 0
@@ -214,41 +216,60 @@ const fetchTimesAndPathsForNetworkAtCoordinate = (network, coordinate, currentZo
214
216
]
215
217
}
216
218
217
- const fetchTimesAndPathsForNetworkAtIndex = ( network , originPoint , index ) =>
218
- fetchMultiple ( {
219
- fetches : [
220
- {
221
- url : `${ network . url } /${ index } _times.dat`
222
- } ,
223
- {
224
- url : `${ network . url } /${ index } _paths.dat`
225
- }
226
- ] ,
227
- next : ( error , responses ) => {
219
+ const fetchTimesAndPathsForNetworkAtIndex = ( network , originPoint , index ) => [
220
+ setNetwork ( {
221
+ ...network ,
222
+ originPoint,
223
+ paths : null ,
224
+ pathsPerTarget : null ,
225
+ targets : null ,
226
+ travelTimeSurface : null
227
+ } ) ,
228
+ fetch ( {
229
+ url : cacheURL ( `${ network . url } /${ index } _paths.dat` ) ,
230
+ next : ( error , response ) => {
228
231
if ( error ) {
229
232
console . error ( error )
230
- if ( error . status === 404 ) return logError ( 'Data not available for these coordinates.' )
231
- return logError ( 'Error while retrieving data for these coordinates.' )
233
+ return logError ( error . status === 400
234
+ ? 'Paths data not available for these coordinates.'
235
+ : 'Error while retrieving paths for these coordinates.' )
232
236
}
233
237
234
- const [ timesResponse , pathsResponse ] = responses
235
- const travelTimeSurface = parseTimesData ( timesResponse . value )
236
- const { paths, pathsPerTarget, targets} = parsePathsData ( pathsResponse . value )
238
+ const { paths, pathsPerTarget, targets} = parsePathsData ( response . value )
237
239
238
- if ( process . env . NODE_ENV === 'development ' ) {
240
+ if ( process . env . NODE_ENV === 'test ' ) {
239
241
warnForInvalidPaths ( paths , network . transitive )
240
242
}
241
243
242
244
return [
243
- logItem ( `Found times and paths for ${ index } ...` ) ,
245
+ logItem ( `Found paths for ${ index } ...` ) ,
244
246
setNetwork ( {
245
- ...network ,
246
- originPoint,
247
+ name : network . name ,
247
248
paths,
248
249
pathsPerTarget,
249
- targets,
250
+ targets
251
+ } )
252
+ ]
253
+ }
254
+ } ) ,
255
+ fetch ( {
256
+ url : cacheURL ( `${ network . url } /${ index } _times.dat` ) ,
257
+ next : ( error , timesResponse ) => {
258
+ if ( error ) {
259
+ console . error ( error )
260
+ return logError ( error . status === 400
261
+ ? 'Data not available for these coordinates.'
262
+ : 'Error while retrieving data for these coordinates.' )
263
+ }
264
+
265
+ const travelTimeSurface = parseTimesData ( timesResponse . value )
266
+ return [
267
+ logItem ( `Found times for ${ index } ...` ) ,
268
+ setNetwork ( {
269
+ name : network . name ,
250
270
travelTimeSurface
251
271
} )
252
272
]
253
273
}
254
274
} )
275
+ ]
0 commit comments