Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 1662 | Rev 2194 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |

import { axios } from '../../utils'
import { feedActionTypes } from './feed.types'

export const setTimelineUrl = (url) => ({
  type: feedActionTypes.SET_TIMELINE_URL,
  payload: url
})

export const loadFeeds = () => ({
  type: feedActionTypes.LOAD_FEEDS
})

export const loadFeedsSuccess = (feeds, currentPage, pages) => ({
  type: feedActionTypes.LOAD_FEEDS_SUCCESS,
  payload: { feeds, currentPage, pages }
})

export const addFeed = (feed, feedSharedId = '') => ({
  type: feedActionTypes.ADD_FEED,
  payload: { feed, feedSharedId }
})

export const updateFeed = ({ feed, uuid }) => ({
  type: feedActionTypes.UPDATE_FEED,
  payload: { feed, uuid }
})
export const deleteFeed = (feedId) => ({
  type: feedActionTypes.DELETE_FEED,
  payload: feedId
})

export const setCurrentPage = (page) => ({
  type: feedActionTypes.SET_CURRENT_PAGE,
  payload: page
})

export const fetchFeeds = (url, page) => {
  return (dispatch) => {
    if (!url || url.includes('undefined')) {
      return
    }

    dispatch(loadFeeds())

    axios
      .get(url + '?page=' + page)
      .then(({ data: response }) => {
        const { data, success } = response

        if (!success) {
          return
        }
        const feeds = data.current.items
        const currentPage = data.current.page
        const pages = data.total.pages

        dispatch(loadFeedsSuccess(feeds, currentPage, pages))
      })
      .catch((err) => {
        console.log(err)
        throw new Error(err)
      })
  }
}

export const removeComment = ({ feedId, commentId }) => ({
  type: feedActionTypes.REMOVE_COMMENT,
  payload: { feedId, commentId }
})

export const addComment = ({ feedId, comment }) => ({
  type: feedActionTypes.ADD_COMMENT,
  payload: { feedId, comment }
})