2017-06-26 15:35:54 +02:00
|
|
|
/*
|
|
|
|
* Prefix Lookup Reducer
|
|
|
|
*/
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
import {LOAD_RESULTS_REQUEST,
|
|
|
|
LOAD_RESULTS_SUCCESS,
|
|
|
|
LOAD_RESULTS_ERROR}
|
|
|
|
from './actions'
|
2017-05-16 13:34:00 +02:00
|
|
|
|
|
|
|
const initialState = {
|
2017-06-26 15:35:54 +02:00
|
|
|
query: '',
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
results: [],
|
|
|
|
error: null,
|
2017-06-28 14:02:54 +02:00
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
queryDurationMs: 0.0,
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2017-06-28 14:02:54 +02:00
|
|
|
limit: 100,
|
|
|
|
offset: 0,
|
|
|
|
totalRoutes: 0,
|
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
isLoading: false
|
2017-05-16 13:34:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function reducer(state=initialState, action) {
|
2017-06-26 15:35:54 +02:00
|
|
|
switch(action.type) {
|
|
|
|
case LOAD_RESULTS_REQUEST:
|
|
|
|
return Object.assign({}, state, initialState, {
|
2017-06-26 22:48:02 +02:00
|
|
|
query: action.payload.query,
|
|
|
|
isLoading: true
|
2017-06-26 15:35:54 +02:00
|
|
|
});
|
|
|
|
case LOAD_RESULTS_SUCCESS:
|
2017-07-04 12:07:03 +02:00
|
|
|
if (state.query != action.payload.query) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
return Object.assign({}, state, {
|
|
|
|
isLoading: false,
|
2017-06-26 22:48:02 +02:00
|
|
|
query: action.payload.query,
|
2017-06-26 15:35:54 +02:00
|
|
|
queryDurationMs: action.payload.results.query_duration_ms,
|
|
|
|
results: action.payload.results.routes,
|
2017-06-28 14:02:54 +02:00
|
|
|
limit: action.payload.results.limit,
|
|
|
|
offset: action.payload.results.offset,
|
|
|
|
totalRoutes: action.payload.results.total_routes,
|
|
|
|
error: null
|
2017-06-26 15:35:54 +02:00
|
|
|
});
|
2017-07-04 12:07:03 +02:00
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
case LOAD_RESULTS_ERROR:
|
2017-07-04 12:07:03 +02:00
|
|
|
if (state.query != action.payload.query) {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
return Object.assign({}, state, initialState, {
|
2017-06-26 22:48:02 +02:00
|
|
|
query: action.payload.query,
|
|
|
|
error: action.payload.error
|
2017-06-26 15:35:54 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return state;
|
2017-05-16 13:34:00 +02:00
|
|
|
}
|
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
|