{"size": 901, "ext": "js", "max_stars_repo_path": "src/redux/stock/stockReducer.js", "max_stars_repo_name": "brugobi/stock-react-capstone", "max_stars_repo_stars_event_min_datetime": "2021-05-25T15:43:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-08T09:43:11.000Z", "max_issues_repo_path": "src/redux/stock/stockReducer.js", "max_issues_repo_name": "brugobi/stock-react-capstone", "max_issues_repo_issues_event_min_datetime": "2021-05-07T14:21:23.000Z", "max_issues_repo_issues_event_max_datetime": "2021-05-20T21:12:03.000Z", "max_forks_repo_path": "src/redux/stock/stockReducer.js", "max_forks_repo_name": "brugobi/stock-react-capstone", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 5, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 18.02, "max_line_length": 56, "alphanum_fraction": 0.5571587125}
import {
  FETCH_STOCK_REQUEST,
  FETCH_STOCK_SUCCESS,
  FETCH_STOCK_FAILURE,
  FETCH_COMPANY_SUCCESS,
} from './stockTypes';

const initialState = {
  loading: false,
  stocks: [],
  company: [],
  error: '',
};

const stockReducer = (state = initialState, action) => {
  switch (action.type) {
    case FETCH_STOCK_REQUEST:
      return {
        ...state,
        loading: true,
      };
    case FETCH_STOCK_SUCCESS:
      return {
        ...state,
        loading: false,
        stocks: action.payload,
        error: '',
      };

    case FETCH_COMPANY_SUCCESS:
      return {
        ...state,
        loading: false,
        company: action.payload,
        error: '',
      };

    case FETCH_STOCK_FAILURE:
      return {
        ...state,
        loading: false,
        stocks: [],
        error: action.payload,
      };
    default: return state;
  }
};

export default stockReducer;
