diff options
author | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:04:27 +0200 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2018-06-28 14:04:27 +0200 |
commit | ecc6e06e92f23b16817985e87b2e997b754f527d (patch) | |
tree | 38eed15bfb8fe63113a8db7e71daf1229cb2425d /src/client/react/store | |
parent | 9efc432e160b429a0643c38e28140bcf42af30a7 (diff) |
Move setWeek to an action
Diffstat (limited to 'src/client/react/store')
-rw-r--r-- | src/client/react/store/actions.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/client/react/store/actions.js b/src/client/react/store/actions.js index c4cc9ba..30b573c 100644 --- a/src/client/react/store/actions.js +++ b/src/client/react/store/actions.js @@ -1,12 +1,39 @@ import users from '../users'; +export function setUser(newUser) { + return (dispatch, getState, getHistory) => { + const { user, updatePathname } = getHistory(); + + if (newUser === user) { + // EDGE CASE: The user is set if the user changes, but it doesn't + // change if the result is already the one we are viewing. + // Causing the <Results /> object to not collapse when a user is + // selected. + // Therefor, we need to dispatch the SET_USER command manually. + dispatch({ type: 'SEARCH/SET_USER', user }); + } else { + updatePathname(newUser); + } + }; +} + +export function setWeek(newWeek) { + return (dispatchEvent, getState, getHistory) => { + const { updateQuery } = getHistory(); + + updateQuery({ + week: newWeek, + }); + }; +} + export function showRoomFinder() { return (dispatch, getState, getHistory) => { - const { user, setUser } = getHistory(); + const { user } = getHistory(); if (user == null || users.byId[user].type !== 'r') { // We are not currently viewing a room, correct the situation. - setUser(users.allRoomIds[0]); + dispatch(setUser(users.allRoomIds[0])); } dispatch({ type: 'ROOM_FINDER/SHOW' }); |