File size: 1,149 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import TVActionTypes from "./tv-types";
import { fetchData, fetchAdditionalTVData } from "../../Services/TvShowService";
import { fetchTvShowsGrid } from "../../Services/TvShowGridService";

export const getTvShowsSuccess = () => ({
  type: TVActionTypes.SET_TV_DATA_SUCCESS
});

export function getTvShows() {
  return dispatch => {
    fetchData().then(data => {
      const TVData = data.map(({ results }) => results);
      var newArray = Array.prototype.concat.apply([], TVData);
      dispatch({
        type: TVActionTypes.SET_TV_DATA,
        payload: newArray
      });
    });
    fetchTvShowsGrid().then(data => {
      const TVGridData = data.map(({ results }) => results[0]);
      var newArray = Array.prototype.concat.apply([], TVGridData);
      dispatch({
        type: TVActionTypes.SET_TV_GRID_DATA,
        payload: newArray
      });
      dispatch(getTvShowsSuccess());
    });
  };
}

export function getAdditionalTVData(id) {
  return dispatch => {
    fetchAdditionalTVData(id).then(data => {
      dispatch({ type: TVActionTypes.SET_TV_ADDITIONAL_DATA, payload: data });
    });
  };
}