{"size": 1551, "ext": "js", "max_stars_repo_path": "hwbounty-forums/src/redux/reducers/dataReducer.js", "max_stars_repo_name": "HWBounty/hwbounty.github.io", "max_stars_repo_stars_event_min_datetime": "2021-02-05T04:47:58.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-06T01:59:09.000Z", "max_issues_repo_path": "hwbounty-forums/src/redux/reducers/dataReducer.js", "max_issues_repo_name": "Homework-Bounty/Homework-Bounty.github.io", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "hwbounty-forums/src/redux/reducers/dataReducer.js", "max_forks_repo_name": "Homework-Bounty/Homework-Bounty.github.io", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.2465753425, "max_line_length": 63, "alphanum_fraction": 0.5538362347}
import {
  SET_BOUNTIES,
  LIKE_BOUNTY,
  UNLIKE_BOUNTY,
  LOADING_DATA,
  DELETE_BOUNTY,
  POST_BOUNTY,
  SET_BOUNTY,
  SUBMIT_COMMENT,
} from "../types";

const initialState = {
  bounties: [],
  bounty: {},
  loading: false,
};

export default function (state = initialState, action) {
  switch (action.type) {
    case LOADING_DATA:
      return {
        ...state,
        loading: true,
      };
    case SET_BOUNTIES:
      return {
        ...state,
        bounties: action.payload,
        loading: false,
      };
    case SET_BOUNTY:
      return {
        ...state,
        bounty: action.payload,
      };
    case LIKE_BOUNTY:
    case UNLIKE_BOUNTY:
      let index = state.bounties.findIndex(
        (bounty) => bounty.bountyId === action.payload.bountyId
      );
      state.bounties[index] = action.payload;
      if (state.bounty.bountyId === action.payload.bountyId) {
        state.bounty = action.payload;
      }
      return {
        ...state,
      };
    case DELETE_BOUNTY:
      let deleteIndex = state.bounties.findIndex(
        (bounty) => bounty.bountyId === action.payload
      );
      state.bounties.splice(deleteIndex, 1);
      return {
        ...state,
      };
    case POST_BOUNTY:
      return {
        ...state,
        bounties: [action.payload, ...state.bounties],
      };
    case SUBMIT_COMMENT:
      return {
        ...state,
        bounty: {
          ...state.bounty,
          comments: [action.payload, ...state.bounty.comments],
        },
      };
    default:
      return state;
  }
}
