aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/reducers
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react/reducers')
-rw-r--r--src/client/react/reducers/view.js43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/client/react/reducers/view.js b/src/client/react/reducers/view.js
index 276d8ae..603f1d4 100644
--- a/src/client/react/reducers/view.js
+++ b/src/client/react/reducers/view.js
@@ -1,3 +1,21 @@
+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: {},
};
@@ -5,25 +23,22 @@ const DEFAULT_STATE = {
const view = (state = DEFAULT_STATE, action) => {
switch (action.type) {
case 'VIEW/FETCH_SCHEDULE_REQUEST':
- return {
- ...state,
- schedules: {
- ...state.schedules,
- [action.user]: {
- state: 'fetching',
- },
- },
- };
case 'VIEW/FETCH_SCHEDULE_SUCCESS':
return {
...state,
schedules: {
...state.schedules,
- [action.user]: {
- ...state.schedules[action.user],
- state: 'finished',
- htmlStr: action.htmlStr,
- },
+ [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: