<commit_before>import request from 'axios';
import { auth, handleError } from 'helpers/requestHelpers';
import { URL } from 'constants/URL';
import FEED from '../constants/Feed';

export const attachStar = data => ({
  type: FEED.ATTACH_STAR,
  data
});

export const clearFeeds = () => ({
  type: FEED.CLEAR
});

export const contentFeedLike = ({ likes, contentId, type }) => ({
  type: FEED.LIKE_CONTENT,
  data: { contentId, type, likes }
});

export const feedCommentDelete = commentId => ({
  type: FEED.DELETE_COMMENT,
  commentId
});

export const feedContentDelete = ({ type, contentId }) => ({
  type: FEED.DELETE_CONTENT,
  contentType: type,
  contentId
});

export const feedCommentEdit = ({ editedComment, commentId }) => ({
  type: FEED.EDIT_COMMENT,
  commentId,
  editedComment
});

export const feedContentEdit = ({ data, contentType, contentId }) => ({
  type: FEED.EDIT_CONTENT,
  data,
  contentType,
  contentId
});

export const feedRewardCommentEdit = ({ id, text }) => ({
  type: FEED.EDIT_REWARD_COMMENT,
  id,
  text
});

export const feedVideoStar = videoId => async dispatch => {
  try {
    const { data } = await request.put(
      `${URL}/video/star`,
      { videoId },
      auth()
    );
    return dispatch({
      type: FEED.STAR_VIDEO,
      videoId,
      isStarred: data
    });
  } catch (error) {
    handleError(error, dispatch);
  }
};

export const fetchFeed = ({ data, feedId }) => ({
  type: FEED.LOAD_DETAIL,
  feedId,
  data
});

export const fetchFeeds = ({
  filter = 'all',
  order = 'desc',
  orderBy = 'lastInteraction',
  username
} = {}) => async dispatch => {
  try {
    const { data } = await request.get(
      `${URL}/content/feeds?filter=${filter}&username=${username}&order=${order}&orderBy=${orderBy}`
    );
    dispatch({
      type: FEED.LOAD,
      data,
      filter
    });
    return Promise.resolve();
  } catch (error) {
    handleError(error, dispatch);
  }
};

export const fetchNewFeeds = data => ({
  type: FEED.LOAD_NEW,
  data
});

export const fetchMoreFeeds = ({
  shownFeeds,
  filter,
  order = 'desc',
  orderBy = 'lastInteraction',
  username
}) => async dispatch => {
  try {
    const { data } = await request.get(
      `${URL}/content/feeds?filter=${filter}&username=${username}${
        shownFeeds ? `&${shownFeeds}` : ''
      }&order=${order}&orderBy=${orderBy}`
    );<commit_msg>filter watched videos when viewing popular starred videos while logged in<commit_after>import request from 'axios';
import { auth, handleError } from 'helpers/requestHelpers';
import { URL } from 'constants/URL';
import FEED from '../constants/Feed';

export const attachStar = data => ({
  type: FEED.ATTACH_STAR,
  data
});

export const clearFeeds = () => ({
  type: FEED.CLEAR
});

export const contentFeedLike = ({ likes, contentId, type }) => ({
  type: FEED.LIKE_CONTENT,
  data: { contentId, type, likes }
});

export const feedCommentDelete = commentId => ({
  type: FEED.DELETE_COMMENT,
  commentId
});

export const feedContentDelete = ({ type, contentId }) => ({
  type: FEED.DELETE_CONTENT,
  contentType: type,
  contentId
});

export const feedCommentEdit = ({ editedComment, commentId }) => ({
  type: FEED.EDIT_COMMENT,
  commentId,
  editedComment
});

export const feedContentEdit = ({ data, contentType, contentId }) => ({
  type: FEED.EDIT_CONTENT,
  data,
  contentType,
  contentId
});

export const feedRewardCommentEdit = ({ id, text }) => ({
  type: FEED.EDIT_REWARD_COMMENT,
  id,
  text
});

export const feedVideoStar = videoId => async dispatch => {
  try {
    const { data } = await request.put(
      `${URL}/video/star`,
      { videoId },
      auth()
    );
    return dispatch({
      type: FEED.STAR_VIDEO,
      videoId,
      isStarred: data
    });
  } catch (error) {
    handleError(error, dispatch);
  }
};

export const fetchFeed = ({ data, feedId }) => ({
  type: FEED.LOAD_DETAIL,
  feedId,
  data
});

export const fetchFeeds = ({
  filter = 'all',
  order = 'desc',
  orderBy = 'lastInteraction',
  username
} = {}) => async dispatch => {
  try {
    const { data } = await request.get(
      `${URL}/content/feeds?filter=${filter}&username=${username}&order=${order}&orderBy=${orderBy}`,
      auth()
    );
    dispatch({
      type: FEED.LOAD,
      data,
      filter
    });
    return Promise.resolve();
  } catch (error) {
    handleError(error, dispatch);
  }
};

export const fetchNewFeeds = data => ({
  type: FEED.LOAD_NEW,
  data
});

export const fetchMoreFeeds = ({
  shownFeeds,
  filter,
  order = 'desc',
  orderBy = 'lastInteraction',
  username
}) => async dispatch => {
  try {
    const { data } = await request.get(
      `${URL}/content/feeds?filter=${filter}&username=${username}${
        shownFeeds ? `&${shownFeeds}` : ''
      }&order=${order}&orderBy=${orderBy}`,
      auth()
    );
{'fraction_non_alphanumeric': 0.15887463798096815, 'fraction_numerical': 0.0, 'mean_word_length': 3.344115004492363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '911881', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1584, 'n_words': 368}