{"size": 1366, "ext": "js", "max_stars_repo_path": "frontend/reducers/trakt-report-reducer.js", "max_stars_repo_name": "ewnd9/media-center", "max_stars_repo_stars_event_min_datetime": "2016-03-20T10:57:38.000Z", "max_stars_repo_stars_event_max_datetime": "2021-07-29T00:55:44.000Z", "max_issues_repo_path": "frontend/reducers/trakt-report-reducer.js", "max_issues_repo_name": "ewnd9/media-center", "max_issues_repo_issues_event_min_datetime": "2015-10-04T10:40:47.000Z", "max_issues_repo_issues_event_max_datetime": "2016-10-31T15:11:23.000Z", "max_forks_repo_path": "frontend/reducers/trakt-report-reducer.js", "max_forks_repo_name": "ewnd9/media-center", "max_forks_repo_forks_event_min_datetime": "2018-12-28T03:54:45.000Z", "max_forks_repo_forks_event_max_datetime": "2021-11-28T11:18:29.000Z"}
{"max_stars_count": 18, "max_issues_count": 5, "max_forks_count": 2, "avg_line_length": 19.2394366197, "max_line_length": 96, "alphanum_fraction": 0.6017569546}
import { createCheckedReducer } from './utils';
import t from 'tcomb';
import moment from 'moment';

import {
  TRAKT_REPORT_REQUEST,
  TRAKT_REPORT_SUCCESS,
  TRAKT_REPORT_FAILURE,

  FETCH_SHOW_REQUEST,
  FETCH_SHOW_SUCCESS,
  FETCH_SHOW_FAILURE
} from '../actions/trakt-report-actions';

export const schema = t.struct({
  isFetching: t.Boolean,
  report: t.maybe(t.list(t.Object)),
  show: t.maybe(t.Object)
});

export default createCheckedReducer({
  isFetching: false,
  report: null,
  show: null
}, {
  [TRAKT_REPORT_REQUEST](state) {
    return {
      ...state,
      isFetching: true
    };
  },
  [TRAKT_REPORT_SUCCESS](state, action) {
    const { report } = action.response;

    report.forEach(report => {
      report.episodes.forEach(ep => {
        // average american show air time
        ep.air_date = moment(`${ep.air_date} 22:00 -05:00`, 'YYYY-MM-DD HH:mm Z').toISOString();
      });
    });

    return {
      ...state,
      isFetching: false,
      report
    };
  },
  [TRAKT_REPORT_FAILURE](state) {
    return {
      ...state,
      isFetching: false
    };
  },
  [FETCH_SHOW_REQUEST](state) {
    return {
      ...state
    };
  },
  [FETCH_SHOW_SUCCESS](state, action) {
    return {
      ...state,
      show: action.response.show
    };
  },
  [FETCH_SHOW_FAILURE](state) {
    return {
      ...state
    };
  },
}, schema);
