aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/store/actions.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/react/store/actions.js')
-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();