{"size": 2165, "ext": "js", "max_stars_repo_path": "client/actions/twitch_actions.js", "max_stars_repo_name": "ch-jin/bundle-app", "max_stars_repo_stars_event_min_datetime": "2017-07-17T06:51:39.000Z", "max_stars_repo_stars_event_max_datetime": "2019-01-06T15:04:03.000Z", "max_issues_repo_path": "client/actions/twitch_actions.js", "max_issues_repo_name": "jinchen93/bundle-app", "max_issues_repo_issues_event_min_datetime": "2019-01-06T15:20:59.000Z", "max_issues_repo_issues_event_max_datetime": "2019-09-23T19:34:47.000Z", "max_forks_repo_path": "client/actions/twitch_actions.js", "max_forks_repo_name": "ch-jin/bundle-app", "max_forks_repo_forks_event_min_datetime": "2019-01-06T15:04:04.000Z", "max_forks_repo_forks_event_max_datetime": "2019-01-06T15:04:04.000Z"}
{"max_stars_count": 6, "max_issues_count": 22, "max_forks_count": 1, "avg_line_length": 29.2567567568, "max_line_length": 76, "alphanum_fraction": 0.7459584296}
// @flow

import * as TwitchAPIUtil from "../utils/twitch_api_util";

export const RECEIVE_TWITCH_FOLLOWS = "RECEIVE_TWITCH_FOLLOWS";
export const RECEIVE_TWITCH_CHANNEL = "RECEIVE_TWITCH_CHANNEL";
export const DELETE_TWITCH_CHANNEL = "DELETE_TWITCH_CHANNEL";
export const RECEIVE_TWITCH_TOP_STREAMS = "RECEIVE_TWITCH_TOP_STREAMS";
export const LOADING_TWITCH_TOP_STREAMS = "LOADING_TWITCH_TOP_STREAMS";
export const RECEIVE_TWITCH_STREAM = "RECEIVE_TWITCH_STREAM";
export const LOADING_TWITCH_STREAM = "LOADING_TWITCH_STREAM";

export const receiveTwitchFollows = (channels: Object) => ({
  type: RECEIVE_TWITCH_FOLLOWS,
  channels,
});

export const receiveTwitchChannel = (channel: Object) => ({
  type: RECEIVE_TWITCH_CHANNEL,
  channel,
});

export const deleteTwitchChannel = (id: number) => ({
  type: DELETE_TWITCH_CHANNEL,
  id,
});

export const receiveTopStreams = (streams: Array<Object>) => ({
  type: RECEIVE_TWITCH_TOP_STREAMS,
  streams,
});

export const loadingTopStreams = () => ({
  type: LOADING_TWITCH_TOP_STREAMS,
});

export const receiveTwitchStream = (stream: Object) => ({
  type: RECEIVE_TWITCH_STREAM,
  stream,
});

export const loadingTwitchStream = () => ({
  type: LOADING_TWITCH_STREAM,
});

export const fetchTwitchFollows = () => (dispatch: Function) =>
  TwitchAPIUtil.fetchTwitchFollows().then(channels =>
    dispatch(receiveTwitchFollows(channels))
  );

export const followTwitchChannel = (name: string) => (dispatch: Function) =>
  TwitchAPIUtil.followTwitchChannel(name).then(channel =>
    dispatch(receiveTwitchChannel(channel))
  );

export const removeTwitchChannel = (id: number) => (dispatch: Function) =>
  TwitchAPIUtil.removeTwitchChannel(id).then(id =>
    dispatch(deleteTwitchChannel(id))
  );

export const fetchTopStreams = () => (dispatch: Function) => {
  dispatch(loadingTopStreams());
  return TwitchAPIUtil.fetchTopStreams().then(streams =>
    dispatch(receiveTopStreams(streams))
  );
};

export const fetchStream = (name: string) => (dispatch: Function) => {
  dispatch(loadingTwitchStream());
  return TwitchAPIUtil.fetchStream(name).then(stream =>
    dispatch(receiveTwitchStream(stream))
  );
};
