1
0
mirror of https://github.com/mgerb/mywebsite synced 2026-01-11 10:22:53 +00:00

redux functionality for sensor page

This commit is contained in:
2016-09-14 20:44:04 +00:00
parent 2f45864fcc
commit e03b3eae25
4 changed files with 75 additions and 20 deletions

View File

@@ -29,6 +29,20 @@ function loadUniqueDates(dates){
}
}
export function setSelectedYearIndex(index){
return{
type: types.SET_SELECTED_YEAR_INDEX,
index
}
}
export function setSelectedMonthIndex(index){
return{
type: types.SET_SELECTED_MONTH_INDEX,
index
}
}
function fetchingList(){
return {
type: types.FETCHING_LIST
@@ -102,9 +116,15 @@ export function fetchUniqueDates(location){
.then(response => response.json())
.then(json => {
dispatch(loadUniqueDates(json));
if(json.length > 0){
let year = json[0].year;
let month = json[0].months[0].monthname;
dispatch(fetchSensorInfoYear(location, year));
dispatch(fetchSensorInfoMonth(location, year, month));
}
})
.catch(error => {
console.log(error);
});
}
}
}

View File

@@ -8,4 +8,8 @@ export const LOAD_UNIQUE_DATES = 'LOAD_UNIQUE_DATES';
export const FETCHING_LIST = 'FETCHING_LIST';
export const FETCHING_INFO_YEAR = 'FETCHING_INFO_YEAR';
export const FETCHING_INFO_MONTH = 'FETCHING_INFO_MONTH';
export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES';
export const FETCHING_UNIQUE_DATES = 'FETCHING_UNIQUE_DATES';
//indexes
export const SET_SELECTED_YEAR_INDEX = 'SET_SELECTED_YEAR_INDEX';
export const SET_SELECTED_MONTH_INDEX = 'SET_SELECTED_MONTH_INDEX';

View File

@@ -8,6 +8,9 @@ const defaultState = {
infoYear: [],
uniqueDates: {},
selectedYearIndex: 0,
selectedMonthIndex: 0,
fetchingList: false,
fetchingInfoMonth: false,
fetchingInfoYear: false,
@@ -69,6 +72,16 @@ export default function app(state = defaultState, action) {
fetchingUniqueDates: false,
fetchedUniqueDates: true
});
//indexes
case types.SET_SELECTED_YEAR_INDEX:
return Object.assign({}, state, {
selectedYearIndex: action.index
});
case types.SET_SELECTED_MONTH_INDEX:
return Object.assign({}, state, {
selectedMonthIndex: action.index
});
}
//return present state if no actions get called
return state;