-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreducer.js
73 lines (65 loc) · 1.63 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const initialState = {
chosenRallies: [],
notChosenRallies: [],
userID: "",
userExp: 0
};
const LOAD_CHOSEN_RALLIES = "LOAD_CHOSEN_RALLIES";
const LOAD_NOT_CHOSEN_RALLIES = "LOAD_NOT_CHOSEN_RALLIES";
const SET_USER_ID = "SET_USER_ID";
const SET_USER_EXP = "SET_USER_EXP";
const ADD_USER_EXP = "ADD_USER_EXP";
const CLEAR_CACHE_ON_LOGOUT = "CLEAR_CACHE_ON_LOGOUT";
const loadChosenRallies = (rallies) => ({
type: LOAD_CHOSEN_RALLIES,
rallies
});
const loadNotChosenRallies = (rallies) => ({
type: LOAD_NOT_CHOSEN_RALLIES,
rallies
});
const setUserID = (userID) => ({
type: SET_USER_ID,
userID
});
const setUserExp = (userExp) => ({
type: SET_USER_EXP,
userExp
});
const addUserExp = (rewardPoints) => ({
type: ADD_USER_EXP,
rewardPoints
});
const clearCacheOnLogout = () => ({
type: CLEAR_CACHE_ON_LOGOUT
});
const reducer = (previousState = initialState, action) => {
switch (action.type) {
case LOAD_CHOSEN_RALLIES:
return { ...previousState, chosenRallies: action.rallies };
case LOAD_NOT_CHOSEN_RALLIES:
return { ...previousState, notChosenRallies: action.rallies };
case SET_USER_ID:
return { ...previousState, userID: action.userID };
case SET_USER_EXP:
return { ...previousState, userExp: action.userExp };
case ADD_USER_EXP:
return {
...previousState,
userExp: previousState.userExp + action.rewardPoints
};
case CLEAR_CACHE_ON_LOGOUT:
return initialState;
default:
return previousState;
}
};
export {
reducer,
loadChosenRallies,
loadNotChosenRallies,
setUserID,
setUserExp,
addUserExp,
clearCacheOnLogout
};