aboutsummaryrefslogtreecommitdiff
path: root/src/client/react/actions/view.js
blob: 79ec14390c2465e6629c8b86e68ab371da8ba770 (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
// eslint-disable-next-line import/prefer-default-export
export const fetchSchedule = (user, week) => (dispatch) => {
  dispatch({
    type: 'VIEW/FETCH_SCHEDULE_REQUEST',
    user,
    week,
  });

  fetch(`/get/${user}?week=${week}`).then(
    // success
    (r) => {
      r.text().then((htmlStr) => {
        dispatch({
          type: 'VIEW/FETCH_SCHEDULE_SUCCESS',
          user,
          week,
          htmlStr,
        });
      });
    },

    // error
    () => {
      dispatch({
        type: 'VIEW/FETCH_SCHEDULE_FAILURE',
        week,
        user,
      });
    },
  );
};