Proyectos de Subversion LeadersLinked - SPA

Rev

Rev 3286 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 3286 Rev 3432
Línea 1... Línea 1...
1
import { axios } from '../../utils'
1
import { axios } from "../../utils";
2
import { feedActionTypes } from './feed.types'
2
import { feedActionTypes } from "./feed.types";
Línea 3... Línea 3...
3
 
3
 
4
export const setTimelineUrl = (url) => ({
4
export const setTimelineUrl = (url) => ({
5
  type: feedActionTypes.SET_TIMELINE_URL,
5
  type: feedActionTypes.SET_TIMELINE_URL,
6
  payload: url
6
  payload: url,
Línea 7... Línea 7...
7
})
7
});
8
 
8
 
9
export const loadFeeds = () => ({
9
export const loadFeeds = () => ({
Línea 10... Línea 10...
10
  type: feedActionTypes.LOAD_FEEDS
10
  type: feedActionTypes.LOAD_FEEDS,
11
})
11
});
12
 
12
 
13
export const loadFeedsSuccess = (feeds, currentPage, pages) => ({
13
export const loadFeedsSuccess = (feeds, currentPage, pages) => ({
Línea 14... Línea 14...
14
  type: feedActionTypes.LOAD_FEEDS_SUCCESS,
14
  type: feedActionTypes.LOAD_FEEDS_SUCCESS,
15
  payload: { feeds, currentPage, pages }
15
  payload: { feeds, currentPage, pages },
16
})
16
});
17
 
17
 
Línea 18... Línea 18...
18
export const addFeed = (url, feed, shareId) => {
18
export const addFeed = (url, feed, shareId) => {
Línea 19... Línea 19...
19
  return async (dispatch) => {
19
  return async (dispatch) => {
20
    const form = new FormData()
20
    const form = new FormData();
Línea 21... Línea 21...
21
    const feedFields = Object.keys(feed)
21
    const feedFields = Object.keys(feed);
22
 
22
 
23
    feedFields.forEach((field) => form.append(field, feed[field]))
23
    feedFields.forEach((field) => form.append(field, feed[field]));
24
 
24
 
Línea 25... Línea 25...
25
    const response = await axios.post(url, form)
25
    const response = await axios.post(url, form);
26
    const { data, success } = response.data
26
    const { data, success } = response.data;
27
 
27
 
Línea 28... Línea 28...
28
    if (!success) {
28
    if (!success) {
29
      const error = typeof data === 'string' ? data : 'Error al publicar'
29
      const error = typeof data === "string" ? data : "Error al publicar";
30
      throw new Error(error)
30
      throw new Error(error);
31
    }
31
    }
Línea 32... Línea 32...
32
 
32
 
33
    dispatch(addFeedSuccess(data, shareId))
33
    dispatch(addFeedSuccess(data, shareId));
34
  }
34
  };
35
}
35
};
Línea 36... Línea 36...
36
 
36
 
37
export const addFeedSuccess = (feed, feedSharedId = '') => ({
37
export const addFeedSuccess = (feed, feedSharedId = "") => ({
38
  type: feedActionTypes.ADD_FEED,
38
  type: feedActionTypes.ADD_FEED,
39
  payload: { feed, feedSharedId }
39
  payload: { feed, feedSharedId },
40
})
40
});
Línea 41... Línea 41...
41
 
41
 
42
export const deleteFeed = (url, id) => {
42
export const deleteFeed = (url, id) => {
43
  return async (dispatch) => {
43
  return async (dispatch) => {
44
    const response = await axios.post(url)
44
    const response = await axios.post(url);
Línea 45... Línea 45...
45
    const { data, success } = response.data
45
    const { data, success } = response.data;
46
 
46
 
47
    if (!success) {
47
    if (!success) {
48
      const err =
48
      const err =
Línea 49... Línea 49...
49
        typeof data === 'string' ? data : 'Error al borrar la publicación'
49
        typeof data === "string" ? data : "Error al borrar la publicación";
50
      throw new Error(err)
50
      throw new Error(err);
51
    }
51
    }
52
 
52
 
Línea 53... Línea 53...
53
    dispatch(deleteFeedSuccess(id))
53
    dispatch(deleteFeedSuccess(id));
54
    return data
54
    return data;
55
  }
55
  };
56
}
56
};
Línea 57... Línea 57...
57
 
57
 
58
export const deleteFeedSuccess = (feedId) => ({
58
export const deleteFeedSuccess = (feedId) => ({
59
  type: feedActionTypes.DELETE_FEED,
59
  type: feedActionTypes.DELETE_FEED,
Línea 60... Línea 60...
60
  payload: feedId
60
  payload: feedId,
Línea 61... Línea 61...
61
})
61
});
62
 
62
 
Línea 63... Línea 63...
63
export const updateFeed = ({ feed, uuid }) => ({
63
export const updateFeed = ({ feed, uuid }) => ({
64
  type: feedActionTypes.UPDATE_FEED,
64
  type: feedActionTypes.UPDATE_FEED,
65
  payload: { feed, uuid }
65
  payload: { feed, uuid },
66
})
66
});
67
 
67
 
Línea 68... Línea 68...
68
export const setCurrentPage = (page) => ({
68
export const setCurrentPage = (page) => ({
69
  type: feedActionTypes.SET_CURRENT_PAGE,
69
  type: feedActionTypes.SET_CURRENT_PAGE,
70
  payload: page
70
  payload: page,
71
})
71
});
72
 
72
 
73
export const fetchFeeds = (url, page) => {
73
export const fetchFeeds = (url, page) => {
74
  return (dispatch) => {
74
  return (dispatch) => {
75
    if (!url || url.includes('undefined')) return
75
    if (!url || url.includes("undefined")) return;
Línea 76... Línea 76...
76
 
76
 
77
    dispatch(loadFeeds())
77
    dispatch(loadFeeds());
78
 
78
 
79
    axios.get(url + '?page=' + page).then(({ data: response }) => {
79
    axios.get(url + "?page=" + page).then((response) => {
Línea 80... Línea 80...
80
      const { data, success } = response
80
      const { data, success } = response.data;
81
 
81
 
82
      if (!success) {
82
      if (!success) {
83
        throw new Error(
83
        throw new Error(