{"size": 861, "ext": "js", "max_stars_repo_path": "src/actions/comments.js", "max_stars_repo_name": "Hommasoft/wappuapp-adminpanel", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/actions/comments.js", "max_issues_repo_name": "Hommasoft/wappuapp-adminpanel", "max_issues_repo_issues_event_min_datetime": "2017-11-26T11:32:57.000Z", "max_issues_repo_issues_event_max_datetime": "2018-02-12T09:04:11.000Z", "max_forks_repo_path": "src/actions/comments.js", "max_forks_repo_name": "Hommasoft/wappuapp-adminpanel", "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.9166666667, "max_line_length": 77, "alphanum_fraction": 0.6213704994}
import * as api from '../services/api';

import {
  GET_COMMENTS_REQUEST,
  GET_COMMENTS_SUCCESS,
  GET_COMMENTS_FAILURE,
  SET_COMMENTS,
  REMOVE_COMMENT
} from './types';

const fetchComments = id => {
  return async dispatch => {
    try {
      dispatch({ type: GET_COMMENTS_REQUEST });
      const response = await api.get({ url: 'feed?parent_id=' + id });
      dispatch({ type: SET_COMMENTS, comments: response.data, open_id: id });
      dispatch({ type: GET_COMMENTS_SUCCESS });
    } catch (error) {
      dispatch({ type: GET_COMMENTS_FAILURE, error: true });
    }
  };
};

const removeComment = id => {
  return async dispatch => {
    try {
      await api.put({ url: 'admin/feed/' + id });
      dispatch({ type: REMOVE_COMMENT, item: id });
    } catch (error) {
      console.log(error);
    }
  };
};

export { fetchComments, removeComment };
