Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 7458 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
7458 stevensc 1
import axios from "axios";
2
import { feedActionTypes } from "./feed.types";
3
 
4
export const setTimelineUrl = (url) => {
5
  return {
6
    type: feedActionTypes.SET_TIMELINE_URL,
7
    payload: url,
8
  };
9
};
10
 
11
export const loadFeeds = () => {
12
  return {
13
    type: feedActionTypes.LOAD_FEEDS,
14
  };
15
};
16
 
17
export const loadFeedsSuccess = (feeds, currentPage, pages) => {
18
  return {
19
    type: feedActionTypes.LOAD_FEEDS_SUCCESS,
20
    payload: { feeds: feeds, currentPage: currentPage, pages: pages },
21
  };
22
};
23
 
24
export const addFeed = (feed, feedSharedId = '') => ({
25
  type: feedActionTypes.ADD_FEED,
26
  payload: { feed: feed, feedSharedId: feedSharedId },
27
});
28
 
29
export const deleteFeed = (feedId) => ({
30
  type: feedActionTypes.DELETE_FEED,
31
  payload: feedId,
32
});
33
 
34
export const setCurrentPage = (page) => ({
35
  type: feedActionTypes.SET_CURRENT_PAGE,
36
  payload: page,
37
});
38
 
39
export const fetchFeeds = (url, page) => {
40
  return (dispatch) => {
41
    dispatch(loadFeeds());
7460 stevensc 42
    axios.get(url, {
43
      params: { page: page }
44
    })
45
      .then(({ data }) => {
46
        if (data.success) {
47
          const feeds = data.data.current.items;
48
          const currentPage = data.data.current.page;
49
          const pages = data.data.total.pages;
7458 stevensc 50
          dispatch(loadFeedsSuccess(feeds, currentPage, pages));
51
        }
52
      })
53
      .catch((error) => {
54
        // dispatch(fetchFeedsFailure());
55
        throw Error(error.message);
56
      });
57
  };
58
};