{"size": 1010, "ext": "js", "max_stars_repo_path": "src/redux/article/actions.js", "max_stars_repo_name": "alekseiliachko/memium_react", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/redux/article/actions.js", "max_issues_repo_name": "alekseiliachko/memium_react", "max_issues_repo_issues_event_min_datetime": "2020-12-13T19:15:09.000Z", "max_issues_repo_issues_event_max_datetime": "2020-12-13T19:15:09.000Z", "max_forks_repo_path": "src/redux/article/actions.js", "max_forks_repo_name": "alekseiliachko/memium_react", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 26.5789473684, "max_line_length": 72, "alphanum_fraction": 0.7207920792}
import ArticlesController from "../../api/ArticlesController";

export const SET_ARTICLE_DATA = "SET_ARTICLE_DATA";
export const setArticleData = (articleId, articleData) => ({
  type: SET_ARTICLE_DATA,
  articleId,
  articleData,
});

export const RESET_ARTICLE_DATA = "RESET_ARTICLE_DATA";
export const resetArticleData = (articleId) => ({
  type: SET_ARTICLE_DATA,
  articleId,
});

export const fetchArticleData = (articleId) => async (dispatch) => {
  const res = await ArticlesController.getArticleById(articleId);
  dispatch(setArticleData(articleId, res.data));
};

export const fetchArticlesByAccountId = async (accountId) => {
  const res = await ArticlesController.getArticleByAccountId(accountId);
  return res.data;
};

export const goToAuthorsPage = (accountId, history) => async (
  dispatch,
  getState
) => {
  const ownId = getState().userReducer?.details?.accountId;

  if (ownId === accountId) {
    history.push("/my-articles");
  } else {
    history.push(`/author/${accountId}`);
  }
};
