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
|
const schedule = (state = {}, action) => {
switch (action.type) {
case 'VIEW/FETCH_SCHEDULE_REQUEST':
return {
...state,
state: 'FETCHING',
};
case 'VIEW/FETCH_SCHEDULE_SUCCESS':
return {
...state,
state: 'FINISHED',
htmlStr: action.htmlStr,
};
default:
return state;
}
};
const DEFAULT_STATE = {
schedules: {},
};
const view = (state = DEFAULT_STATE, action) => {
switch (action.type) {
case 'VIEW/FETCH_SCHEDULE_REQUEST':
case 'VIEW/FETCH_SCHEDULE_SUCCESS':
return {
...state,
schedules: {
...state.schedules,
[action.user]:
state.schedules[action.user]
? {
// This user already exists in our state, extend it.
...state.schedules[action.user],
[action.week]: schedule(state.schedules[action.user][action.week], action),
}
: {
// This user does not already exist in our state.
[action.week]: schedule(undefined, action),
},
},
};
default:
return state;
}
};
export default view;
export const _test = {
DEFAULT_STATE,
};
|