diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:33:04 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:33:04 +0200 |
commit | 8018bbc67b10b7b75589b98ed92c6dda1f6163f4 (patch) | |
tree | 2f6ebd53ee3d8f32fad34de0191d911ddc65757e /src/client/react/store | |
parent | e61429154d4c06e0362abd55482400a45b7636ab (diff) |
Extract shiftWeek from WeekSelector
Diffstat (limited to 'src/client/react/store')
-rw-r--r-- | src/client/react/store/actions.js | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/client/react/store/actions.js b/src/client/react/store/actions.js index 30b573c..46a38ab 100644 --- a/src/client/react/store/actions.js +++ b/src/client/react/store/actions.js @@ -1,7 +1,8 @@ import users from '../users'; +import purifyWeek from '../lib/purifyWeek'; export function setUser(newUser) { - return (dispatch, getState, getHistory) => { + return (dispatch, getState, { getHistory }) => { const { user, updatePathname } = getHistory(); if (newUser === user) { @@ -18,17 +19,26 @@ export function setUser(newUser) { } export function setWeek(newWeek) { - return (dispatchEvent, getState, getHistory) => { + return (dispatch, getState, { getHistory, moment }) => { const { updateQuery } = getHistory(); + const isCurrentWeek = moment().week() === newWeek; + updateQuery({ - week: newWeek, + week: isCurrentWeek ? undefined : newWeek, }); }; } +export function shiftWeek(shift) { + return (dispatch, getState, { getHistory }) => { + const { week } = getHistory(); + dispatch(setWeek(purifyWeek(week + shift))); + }; +} + export function showRoomFinder() { - return (dispatch, getState, getHistory) => { + return (dispatch, getState, { getHistory }) => { const { user } = getHistory(); if (user == null || users.byId[user].type !== 'r') { |