{"size": 1450, "ext": "js", "max_stars_repo_path": "client/src/actions/jobActions.js", "max_stars_repo_name": "rpmoore8/job-search-web-app", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/actions/jobActions.js", "max_issues_repo_name": "rpmoore8/job-search-web-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/actions/jobActions.js", "max_forks_repo_name": "rpmoore8/job-search-web-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.7142857143, "max_line_length": 74, "alphanum_fraction": 0.5737931034}
import axios from "axios";

import { cities, categories, categoryNames } from "./searchParams";
import { GET_JOBS, JOBS_LOADING, CLEAR_CURRENT_JOBS } from "./types";

// Get jobs
export const getJobs = searchData => dispatch => {
  if (
    cities.indexOf(searchData.city) >= 0 &&
    categoryNames.indexOf(searchData.category)
  ) {
    let city = searchData.city;
    let category = categories[categoryNames.indexOf(searchData.category)];
    let address = "/jobs/" + city + "/" + category;
    console.log(address);

    dispatch(setJobsLoading());
    axios
      .get(address)
      .then(res =>
        dispatch({
          type: GET_JOBS,
          payload: res.data
        })
      )
      .catch(err =>
        dispatch({
          type: GET_JOBS,
          payload: null
        })
      );
  } else {
    console.log("ERROR - BAD INPUT");
  }
};

// Get jobs from list of ids
export const getJobsById = searchData => dispatch => {
  console.log(searchData);
  dispatch(setJobsLoading());
  axios
    .post("/jobs/ids", searchData)
    .then(res => {
      dispatch({
        type: GET_JOBS,
        payload: res.data
      });
    })
    .catch(err => {
      dispatch({
        type: GET_JOBS,
        payload: null
      });
    });
};

// Jobs loading
export const setJobsLoading = () => {
  return {
    type: JOBS_LOADING
  };
};

// Clear Jobs
export const clearCurrentJobs = () => {
  return {
    type: CLEAR_CURRENT_JOBS
  };
};
