-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feed): make trip histogram for pattern list
- Loading branch information
1 parent
f11c12a
commit dd858a2
Showing
12 changed files
with
507 additions
and
267 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,64 @@ | ||
// @flow | ||
|
||
import {createAction} from 'redux-actions' | ||
|
||
import {secureFetch} from '../../common/actions' | ||
import {compose, patterns} from '../../gtfs/util/graphql' | ||
import {updateRouteFilter, updatePatternFilter} from './filter' | ||
|
||
import type {Route} from '../reducers/routes' | ||
import type {dispatchFn, getStateFn} from '../../types' | ||
|
||
export const fetchingPatterns = createAction('FETCH_GRAPHQL_PATTERNS') | ||
export const clearPatterns = createAction('CLEAR_GRAPHQL_PATTERNS') | ||
export const errorFetchingPatterns = createAction('FETCH_GRAPHQL_PATTERNS_REJECTED') | ||
export const errorFetchingPatterns = createAction( | ||
'FETCH_GRAPHQL_PATTERNS_REJECTED' | ||
) | ||
export const receivePatterns = createAction('FETCH_GRAPHQL_PATTERNS_FULFILLED') | ||
|
||
export function patternDateTimeFilterChange (namespace, props) { | ||
return function (dispatch, getState) { | ||
const routeId = getState().gtfs.filter.routeFilter | ||
const { date, from, to } = getState().gtfs.filter.dateTimeFilter | ||
dispatch(fetchPatterns(namespace, routeId, date, from, to)) | ||
export function patternDateTimeFilterChange (namespace: string) { | ||
return function (dispatch: dispatchFn, getState: getStateFn) { | ||
const state = getState() | ||
const routeId = state.gtfs.filter.routeFilter | ||
dispatch(fetchPatterns(namespace, routeId)) | ||
} | ||
} | ||
|
||
export function fetchPatterns (namespace, routeId, date, from, to) { | ||
return function (dispatch, getState) { | ||
dispatch(fetchingPatterns({namespace, routeId, date, from, to})) | ||
// FIXME: if routeId is null, clear current routes so we can fetch all routes | ||
export function fetchPatterns (namespace: string, routeId: ?string) { | ||
return function (dispatch: dispatchFn, getState: getStateFn) { | ||
dispatch(fetchingPatterns()) | ||
if (!routeId) { | ||
const routes = [] | ||
return dispatch(receivePatterns({namespace, routes})) | ||
return dispatch(receivePatterns({routes})) | ||
} | ||
return dispatch(secureFetch(compose(patterns, {namespace, routeId, date, from, to}))) | ||
.then((response) => { | ||
const {date, from, to} = getState().gtfs.filter.dateTimeFilter | ||
return dispatch( | ||
secureFetch(compose(patterns, {namespace, routeId, date, from, to})) | ||
) | ||
.then(response => { | ||
if (response.status >= 300) { | ||
return dispatch(errorFetchingPatterns(namespace, routeId)) | ||
return dispatch(errorFetchingPatterns()) | ||
} | ||
return response.json() | ||
}) | ||
.then(json => { | ||
if (json.data) { | ||
const {routes} = json.data.feed | ||
dispatch(receivePatterns({namespace, routes})) | ||
dispatch(receivePatterns({routes})) | ||
} else { | ||
console.log('Error fetching patterns') | ||
} | ||
}) | ||
} | ||
} | ||
|
||
export function patternRouteFilterChange (namespace, routeData) { | ||
return function (dispatch, getState) { | ||
const newRouteId = (routeData && routeData.route_id) ? routeData.route_id : null | ||
const {date, from, to} = getState().gtfs.filter.dateTimeFilter | ||
export function patternRouteFilterChange (namespace: string, routeData: Route) { | ||
return function (dispatch: dispatchFn, getState: getStateFn) { | ||
const newRouteId = | ||
routeData && routeData.route_id ? routeData.route_id : null | ||
dispatch(updateRouteFilter(newRouteId)) | ||
// If there's an active pattern, clear it | ||
dispatch(updatePatternFilter(null)) | ||
dispatch(fetchPatterns(namespace, newRouteId, date, from, to)) | ||
dispatch(fetchPatterns(namespace, newRouteId)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.