diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-01-28 15:43:11 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-01-28 15:43:11 +0100 |
commit | 8670ada517bc8beb69d152c82f282322b9ea8d64 (patch) | |
tree | de3d52fcdf48a69806a41e408065b7f119206610 /src/client/react/reducers | |
parent | 0c99c0b4d84f53675cc3d42fa518879789cc86b0 (diff) |
Implement week selector in the view
Diffstat (limited to 'src/client/react/reducers')
-rw-r--r-- | src/client/react/reducers/view.js | 43 |
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: |