{"size": 1034, "ext": "js", "max_stars_repo_path": "studio/src/reducers/infoReducer.js", "max_stars_repo_name": "chakradhar32/dega", "max_stars_repo_stars_event_min_datetime": "2021-07-09T21:42:56.000Z", "max_stars_repo_stars_event_max_datetime": "2022-02-23T17:25:30.000Z", "max_issues_repo_path": "studio/src/reducers/infoReducer.js", "max_issues_repo_name": "chakradhar32/dega", "max_issues_repo_issues_event_min_datetime": "2021-07-09T18:16:45.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T05:55:14.000Z", "max_forks_repo_path": "studio/src/reducers/infoReducer.js", "max_forks_repo_name": "chakradhar32/dega", "max_forks_repo_forks_event_min_datetime": "2020-11-17T07:58:49.000Z", "max_forks_repo_forks_event_max_datetime": "2020-12-03T13:08:18.000Z"}
{"max_stars_count": 12, "max_issues_count": 386, "max_forks_count": 5, "avg_line_length": 18.4642857143, "max_line_length": 72, "alphanum_fraction": 0.4932301741}
import { ADD_INFO } from '../constants/info';

const initialState = {
  categories: 0,
  tag: 0,
  article: {
    draft: 0,
    template: 0,
    publish: 0,
  },
  factCheck: {
    draft: 0,
    template: 0,
    publish: 0,
  },
  podcasts: 0,
};

export default function infoReducer(state = initialState, action = {}) {
  if (!action.payload) {
    return state;
  }
  switch (action.type) {
    case ADD_INFO:
      const posts = action.payload.posts;
      let article = {
        draft: 0,
        template: 0,
        publish: 0,
        ready: 0,
      };
      let factCheck = {
        draft: 0,
        template: 0,
        publish: 0,
        ready: 0,
      };

      posts.forEach((each) => {
        if (each.slug === 'article') {
          article[each.status] = each.count;
        }
        if (each.slug === 'fact-check') {
          factCheck[each.status] = each.count;
        }
      });
      return {
        ...action.payload,
        article,
        factCheck,
      };
    default:
      return state;
  }
}
