{"size": 1246, "ext": "js", "max_stars_repo_path": "app/containers/HomePage/reducer.js", "max_stars_repo_name": "sangzc/DMI_React", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/containers/HomePage/reducer.js", "max_issues_repo_name": "sangzc/DMI_React", "max_issues_repo_issues_event_min_datetime": "2020-07-17T08:45:08.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-02T19:04:09.000Z", "max_forks_repo_path": "app/containers/HomePage/reducer.js", "max_forks_repo_name": "sangzc/DMI_React", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 3, "max_forks_count": null, "avg_line_length": 23.5094339623, "max_line_length": 84, "alphanum_fraction": 0.6781701445}
/*
 * HomeReducer
 *
 * The reducer takes care of our data. Using actions, we can
 * update our application state. To add a new action,
 * add it to the switch statement in the reducer function
 *
 */

import {
  GET_COLORS_SUCCESS,
  GET_COLORS_REQUEST,
  GET_COLORS_ERROR,
} from './constants';
import {
  ADD_NEW_COLOR_SUCCESS,
  ADD_NEW_COLOR_REQUEST,
  ADD_NEW_COLOR_ERROR,
} from '../ColorPage/constants';

// The initial state of the App
export const initialState = {
  colors: [],
  isLoading: true,
  initialLoad: true,
};

/* eslint-disable default-case, no-param-reassign */
export default function homeReducer(state = initialState, action = {}) {
  switch (action.type) {
    case GET_COLORS_REQUEST:
      return { ...state, isLoading: true };

    case GET_COLORS_SUCCESS:
      return { colors: [...action.response], isLoading: false, initialLoad: false };

    case GET_COLORS_ERROR:
      return { ...state, isLoading: false };

    case ADD_NEW_COLOR_REQUEST:
      return { ...state, isLoading: true };

    case ADD_NEW_COLOR_SUCCESS:
      return { ...state, colors: [...action.response], isLoading: false };

    case ADD_NEW_COLOR_ERROR:
      return { ...state, isLoading: false };

    default:
      return state;
  }
}
