{"size": 2651, "ext": "js", "max_stars_repo_path": "src/actions/userEpisodesWatched.js", "max_stars_repo_name": "Brandoncyu/tvod-frontend", "max_stars_repo_stars_event_min_datetime": "2018-10-31T01:45:15.000Z", "max_stars_repo_stars_event_max_datetime": "2018-12-14T02:51:08.000Z", "max_issues_repo_path": "src/actions/userEpisodesWatched.js", "max_issues_repo_name": "Brandoncyu/tvod-frontend", "max_issues_repo_issues_event_min_datetime": "2020-09-04T14:17:39.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-08T22:26:19.000Z", "max_forks_repo_path": "src/actions/userEpisodesWatched.js", "max_forks_repo_name": "Brandoncyu/tvod-frontend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": 12, "max_forks_count": null, "avg_line_length": 27.6145833333, "max_line_length": 152, "alphanum_fraction": 0.6661637118}
import {getEpisodes, addEpisodeToDatabase, addCommentToDatabase, addMultipleEpisodeToDatabase, addRatingToDatabase} from '../models/userEpisodesWatched'
export const GET_EPISODES = 'GET_EPISODES'
export const ADD_EPISODE = 'ADD_EPISODE'
export const ADD_COMMENT = 'ADD_COMMENT'
export const ADD_RATING = 'ADD_RATING'
export const ADD_MULTIPLE_EPISODES = 'ADD_MULTIPLE_EPISODES'
export const CLEAR_WATCHED = 'CLEAR_WATCHED'

export const getAllEpisodes = (userid, tvId) =>{
  return async (dispatch) => {
    let response = await getEpisodes(userid, tvId)
    const epInfo = {
      episodeInfo: response,
      episodeIds: response.filter(element => element.watched === true).map(element => element['ep_id'])
    }
    dispatch({
      type: GET_EPISODES,
      payload: epInfo
    })
  }
}

export const addEpisode = (userId, tvId, tvName, image, epId, seasonNo, epNo, epName) =>{
  return async (dispatch) => {
    let response = await addEpisodeToDatabase(userId, tvId, tvName, image, epId, seasonNo, epNo, epName)

    const epInfo = {
      episodeInfo: response,
      episodeIds: response.filter(element => element.watched === true).map(element => element['ep_id'])
    }
    dispatch({
      type: ADD_EPISODE,
      payload: epInfo
    })
  }
}

export const addMultipleEpisodes = (userId, tvId, episodeArray) =>{
  return async (dispatch) => {

    let response = await addMultipleEpisodeToDatabase(userId, tvId, episodeArray)

    const epInfo = {
      episodeInfo: response,
      episodeIds: response.filter(element => element.watched === true).map(element => element['ep_id'])
    }
    dispatch({
      type: ADD_MULTIPLE_EPISODES,
      payload: epInfo
    })
  }
}

export const addComment = (userId, tvId, epId, comment) =>{
  return async (dispatch) =>{
    let response = await addCommentToDatabase(userId, tvId, epId, comment)

    const epInfo = {
      episodeInfo: response,
      episodeIds: response.filter(element => element.watched === true).map(element => element['ep_id'])
    }

    dispatch({
      type: ADD_COMMENT,
      payload: epInfo
    })
  }
}

export const addRating = (userId, tvId, epId, rating) =>{
  return async (dispatch) =>{
    let response = await addRatingToDatabase(userId, tvId, epId, rating)

    const epInfo = {
      episodeInfo: response,
      episodeIds: response.filter(element => element.watched === true).map(element => element['ep_id'])
    }

    dispatch({
      type: ADD_RATING,
      payload: epInfo
    })
  }
}


export const clearEpisodes = () => {
  return (dispatch) =>{
    let response = false
    dispatch({
      type: CLEAR_WATCHED,
      payload: response
    })
  }
}
