aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/store
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2018-07-03 20:09:24 +0200
committerNoah Loomans <noahloomans@gmail.com>2018-07-03 20:14:11 +0200
commitf5c7fc1c6aa985151cf9f151d2f3423772d6fc09 (patch)
treef91072de9c3a7067c037109e68e0880113624baf /src/client/react/store
parent8f7bcf27d6ad8e3d13114bd60c942fa8cce279f8 (diff)
client/RoomFinder: Refactor
Diffstat (limited to 'src/client/react/store')
-rw-r--r--src/client/react/store/actions.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/client/react/store/actions.js b/src/client/react/store/actions.js
index b123a8b..96256e4 100644
--- a/src/client/react/store/actions.js
+++ b/src/client/react/store/actions.js
@@ -18,6 +18,29 @@ export function setUser(newUser) {
};
}
+export function shiftRoom(shift) {
+ return (dispatch, getState, { getHistory }) => {
+ const { user } = getHistory();
+ const { allRoomIds } = users;
+
+ if (users.byId[user].type !== 'r') throw new Error('User must be a room');
+
+ const currentRoom = user;
+ const currentRoomIndex = allRoomIds.indexOf(currentRoom);
+
+ let nextRoomIndex = currentRoomIndex + shift;
+
+ if (nextRoomIndex < 0) {
+ nextRoomIndex = allRoomIds.length - 1;
+ } else if (nextRoomIndex > allRoomIds.length - 1) {
+ nextRoomIndex = 0;
+ }
+
+ const nextRoom = allRoomIds[nextRoomIndex];
+ dispatch(setUser(nextRoom));
+ };
+}
+
export function setWeek(newWeek) {
return (dispatch, getState, { getHistory, moment }) => {
const { updateQuery } = getHistory();