aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/store/actions.js
blob: 30b573c72e9c1b3f773c58c62c86bfa2441c2e27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 } = getHistory();

    if (user == null || users.byId[user].type !== 'r') {
      // We are not currently viewing a room, correct the situation.
      dispatch(setUser(users.allRoomIds[0]));
    }

    dispatch({ type: 'ROOM_FINDER/SHOW' });
  };
}