Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 1 | Rev 5310 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1018 stevensc 1
import { axios } from "../../utils";
1 www 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
 
1018 stevensc 24
export const addFeed = (feed, feedSharedId = '') => ({
1 www 25
  type: feedActionTypes.ADD_FEED,
1018 stevensc 26
  payload: { feed: feed, feedSharedId: feedSharedId },
1 www 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) => {
1018 stevensc 40
  (url);
1 www 41
  return (dispatch) => {
42
    dispatch(loadFeeds());
43
    axios
1018 stevensc 44
      .get(url + '?page=' + page)
1 www 45
      .then((res) => {
46
        const resData = res.data;
1018 stevensc 47
        (resData);
1 www 48
        const feeds = resData.data.current.items;
49
        const currentPage = resData.data.current.page;
50
        const pages = resData.data.total.pages;
51
        if (resData.success) {
52
          dispatch(loadFeedsSuccess(feeds, currentPage, pages));
53
        }
54
      })
55
      .catch((error) => {
56
        // dispatch(fetchFeedsFailure());
57
        throw Error(error.message);
58
      });
59
  };
60
};