1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

86 lines
1.8 KiB
React
Raw Normal View History

2018-09-09 17:44:44 +02:00
/*
* This will migrate to become the neighbors
* reducer. Currently neihgbors are stored in
* the routeserver reducer.
*/
2018-09-16 19:56:22 +02:00
import {SET_FILTER_VALUE} from './actions'
2018-09-09 17:44:44 +02:00
2018-10-02 10:48:57 +02:00
import {LOAD_ROUTESERVER_PROTOCOL_REQUEST,
LOAD_ROUTESERVER_PROTOCOL_SUCCESS,
LOAD_ROUTESERVER_PROTOCOL_ERROR}
from '../actions'
2018-09-16 19:56:22 +02:00
const LOCATION_CHANGE = '@@router/LOCATION_CHANGE';
2018-09-09 17:44:44 +02:00
const DEFAULT_SORT_COLUMN = "asn";
const DEFAULT_SORT_ORDER = "asc";
const initialState = {
sortColumn: DEFAULT_SORT_COLUMN,
sortOrder: DEFAULT_SORT_ORDER,
2018-09-16 19:56:22 +02:00
2018-10-02 10:48:57 +02:00
isLoading: false,
cachedAt: null,
cacheTtl: null,
2018-09-16 19:56:22 +02:00
filterQuery: "",
filterValue: ""
2018-09-09 17:44:44 +02:00
};
// Reducer functions
function _handleLocationChange(state, payload) {
const query = payload.query;
const sort = query["s"] || DEFAULT_SORT_COLUMN;
const order = query["o"] || DEFAULT_SORT_ORDER;
2018-09-16 19:56:22 +02:00
const filterQuery = query["q"] || "";
2018-09-09 17:44:44 +02:00
return Object.assign({}, state, {
sortColumn: sort,
2018-09-16 19:56:22 +02:00
sortOrder: order,
filterQuery: filterQuery,
filterValue: filterQuery
2018-09-09 17:44:44 +02:00
});
}
export default function(state=initialState, action) {
switch (action.type) {
case LOCATION_CHANGE:
return _handleLocationChange(state, action.payload);
2018-09-16 19:56:22 +02:00
case SET_FILTER_VALUE:
return Object.assign({}, state, {
filterValue: action.payload.value
});
2018-10-02 10:48:57 +02:00
case LOAD_ROUTESERVER_PROTOCOL_REQUEST:
return Object.assign({}, state, {
isLoading: true,
});
case LOAD_ROUTESERVER_PROTOCOL_ERROR:
return Object.assign({}, state, {
isLoading: false,
});
// TODO: move neighbors list here
case LOAD_ROUTESERVER_PROTOCOL_SUCCESS:
return Object.assign({}, state, {
isLoading: false,
cachedAt: action.payload.api.cache_status.cached_at,
cacheTtl: action.payload.api.ttl,
});
2018-09-09 17:44:44 +02:00
default:
}
return state;
}