-
Notifications
You must be signed in to change notification settings - Fork 0
/
reducer.js
59 lines (54 loc) · 1.46 KB
/
reducer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
export const SET_LOCATION = 'SET_LOCATION';
export const SET_DATE_RANGE = 'SET_DATE_RANGE';
export const GET_PRESSURE_DATA = 'GET_PRESSURE_DATA';
export const GET_PRESSURE_DATA_SUCCESS = 'GET_PRESSURE_DATA_SUCCESS';
export const GET_PRESSURE_DATA_FAIL = 'GET_PRESSURE_DATA_FAIL';
const defaultState = {
lat: null,
lng: null,
startDate: null,
endDate: null,
pressureData: [],
error: false,
loading: false
}
export default function reducer(state = defaultState, action) {
switch (action.type) {
case SET_LOCATION:
return { ...state, lat: action.lat, lng: action.lng };
case SET_DATE_RANGE:
return { ...state, startDate: action.startDate, endDate: action.endDate };
case GET_PRESSURE_DATA:
return { ...state, loading: true };
case GET_PRESSURE_DATA_SUCCESS:
return { ...state, loading: false, pressureData: action.payload.data };
case GET_PRESSURE_DATA_FAIL:
return { ...state, loading: false, error: action.payload.error };
default:
return state;
}
}
export function getPressureData(lat, lng, startDate, endDate) {
return {
type: GET_PRESSURE_DATA,
payload: {
request: {
url: `/pressure?lat=${lat}&long=${lng}&dateStart=${startDate}&dateEnd=${endDate}`
}
}
};
}
export function setDateRange(startDate, endDate) {
return {
type: SET_DATE_RANGE,
startDate,
endDate
};
}
export function setLocation(lat, lng) {
return {
type: SET_LOCATION,
lat,
lng
};
}