diff --git a/client/js/components/sensors/SensorInfo.js b/client/js/components/sensors/SensorInfo.js
index c45bd2f..84b46e3 100644
--- a/client/js/components/sensors/SensorInfo.js
+++ b/client/js/components/sensors/SensorInfo.js
@@ -1,34 +1,52 @@
import React from 'react';
-let location, sensor, actions, uniqueDates;
+let location, sensor, actions, uniqueDates, fetchedAll;
export default class SensorInfo extends React.Component{
componentDidMount(){
location = this.props.params.location;
- actions = this.props.sensorActions;
- sensor = this.props.sensor;
-
- actions.fetchUniqueDates(location);
-
- /*
- this.props.sensorActions.fetchSensorInfoYear('Grand Meadow', '2016');
- this.props.sensorActions.fetchSensorInfoMonth('Grand Meadow', '2016', 'May');
- this.props.sensorActions.fetchUniqueDates('Grand Meadow');
- */
+ this.props.sensorActions.fetchUniqueDates(location);
}
- componentWillReceiveProps(){
- if(sensor.fetchedUniqueDates){
- uniqueDates = sensor.uniqueDates;
-
- //!sensor.fetchedInfoMonth ? actions.fetchSensorInfoMonth(location, )
- }
+ loadYearOptions = (date, index) => {
+ return (
+
+ );
+ }
+
+ loadMonthOptions = (date, index) => {
+ return (
+
+ );
+ }
+
+ onYearChange(event){
+ this.props.sensorActions.setSelectedYearIndex(parseInt(event.target.value));
+ }
+
+ onMonthChange(event){
+ this.props.sensorActions.setSelectedMonthIndex(parseInt(event.target.value));
}
render(){
+ sensor = this.props.sensor;
return(
-
Test123
+
+
+
+
+
);
}
}
\ No newline at end of file
diff --git a/client/js/redux/actions/sensor.js b/client/js/redux/actions/sensor.js
index 3467e8d..3394c55 100644
--- a/client/js/redux/actions/sensor.js
+++ b/client/js/redux/actions/sensor.js
@@ -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);
});
}
-}
\ No newline at end of file
+}
diff --git a/client/js/redux/constants/sensor.js b/client/js/redux/constants/sensor.js
index 39587d0..a277743 100644
--- a/client/js/redux/constants/sensor.js
+++ b/client/js/redux/constants/sensor.js
@@ -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';
\ No newline at end of file
+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';
\ No newline at end of file
diff --git a/client/js/redux/reducers/sensor.js b/client/js/redux/reducers/sensor.js
index 3b28d23..5d74606 100644
--- a/client/js/redux/reducers/sensor.js
+++ b/client/js/redux/reducers/sensor.js
@@ -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;