mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 10:52:47 +00:00
76 lines
2.3 KiB
JavaScript
76 lines
2.3 KiB
JavaScript
//import typs
|
|
import * as types from '../constants/sensor';
|
|
|
|
//defaults -
|
|
const defaultState = {
|
|
list : [],
|
|
infoMonth: [],
|
|
infoYear: [],
|
|
uniqueDates: {},
|
|
|
|
fetchingList: false,
|
|
fetchingInfoMonth: false,
|
|
fetchingInfoYear: false,
|
|
fetchingUniqueDates: false,
|
|
|
|
fetchedList: false,
|
|
fetchedInfoMonth: false,
|
|
fetchedInfoYear: false,
|
|
fetchedUniqueDates: false
|
|
};
|
|
|
|
//default reducer
|
|
export default function app(state = defaultState, action) {
|
|
switch(action.type){
|
|
//fetching functions - we use a fetching state to display loading images
|
|
case types.FETCHING_LIST:
|
|
return Object.assign({}, state, {
|
|
fetchingList: true,
|
|
fetchedList: false
|
|
});
|
|
case types.FETCHING_INFO_MONTH:
|
|
return Object.assign({}, state, {
|
|
fetchingInfoMonth: true,
|
|
fetchedInfoMonth: false
|
|
});
|
|
case types.FETCHING_INFO_YEAR:
|
|
return Object.assign({}, state, {
|
|
fetchingInfoYear: true,
|
|
fetchedInfoYear: false
|
|
});
|
|
case types:FETCHING_UNIQUE_DATES:
|
|
return Object.assign({}, state, {
|
|
fetchingUniqueDates: true,
|
|
fetchedUniqueDates: false
|
|
});
|
|
|
|
//other functions
|
|
case types.LOAD_SENSOR_LIST:
|
|
return Object.assign({}, state, {
|
|
list: action.sensor_list,
|
|
fetchingList: false,
|
|
fetchedList: true
|
|
});
|
|
case types.LOAD_SENSOR_INFO_MONTH:
|
|
return Object.assign({}, state, {
|
|
infoMonth: action.sensor_info,
|
|
fetchingInfoMonth: false,
|
|
fetchedInfoMonth: true
|
|
});
|
|
case types.LOAD_SENSOR_INFO_YEAR:
|
|
return Object.assign({}, state, {
|
|
infoYear: action.sensor_info,
|
|
fetchingInfoYear: false,
|
|
fetchedInfoYear: true
|
|
});
|
|
case types.LOAD_UNIQUE_DATES:
|
|
return Object.assign({}, state, {
|
|
uniqueDates: action.dates,
|
|
fetchingUniqueDates: false,
|
|
fetchedUniqueDates: true
|
|
});
|
|
}
|
|
//return present state if no actions get called
|
|
return state;
|
|
}
|