{"size": 1119, "ext": "js", "max_stars_repo_path": "client/src/redux/actions/locationActions.js", "max_stars_repo_name": "twkirkpatrick/react-nomadic", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "client/src/redux/actions/locationActions.js", "max_issues_repo_name": "twkirkpatrick/react-nomadic", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "client/src/redux/actions/locationActions.js", "max_forks_repo_name": "twkirkpatrick/react-nomadic", "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": 17.7619047619, "max_line_length": 62, "alphanum_fraction": 0.618409294}
import {
  ADD_LOCATION,
  REMOVE_LOCATION,
  OPEN_LOCATION_MODAL,
  CLOSE_LOCATION_MODAL,
  SET_CURRENT,
  GET_LOCATIONS,
  SET_LOADING
} from "./types";
import axios from "axios";

export const getLocations = () => async (dispatch) => {
  try {
    setLoading();
    const res = await axios.get("/api/locations");
    dispatch({
      type: GET_LOCATIONS,
      payload: res.data
    });
  } catch (err) {
    console.error("something went wrong");
  }
};

export const addLocation = (location) => async (dispatch) => {
  try {
    setLoading();
    const res = await axios.post("/api/locations", location);

    dispatch({
      type: ADD_LOCATION,
      payload: res.data
    });
  } catch (err) {
    console.error("something went wrong");
  }
};

export const setCurrent = (location) => {
  return {
    type: SET_CURRENT,
    payload: location
  };
};

export const openLocationModal = () => {
  return {
    type: OPEN_LOCATION_MODAL
  };
};

export const closeLocationModal = () => {
  return {
    type: CLOSE_LOCATION_MODAL
  };
};

export const setLoading = () => {
  return {
    type: SET_LOADING
  };
};
