aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/reducers/view.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-01-29 16:31:05 +0100
committerGitHub <noreply@github.com>2018-01-29 16:31:05 +0100
commit694580bc532239a32c2fbf61d7f09e793fd1cb11 (patch)
treeacd21e2654d6c5e70dc41c675972794ce95b4062 /src/client/react/reducers/view.js
parentf18692872cdc28d29917247ef4f8ef7553a8b023 (diff)
parent9a9edd1865d619caada787231c8bb34be25af3af (diff)
Merge pull request #15 from nloomans/react
Move project over to react
Diffstat (limited to 'src/client/react/reducers/view.js')
-rw-r--r--src/client/react/reducers/view.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/client/react/reducers/view.js b/src/client/react/reducers/view.js
new file mode 100644
index 0000000..301a1cf
--- /dev/null
+++ b/src/client/react/reducers/view.js
@@ -0,0 +1,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,
+};