Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5331 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 5331 Rev 6359
Línea 5... Línea 5...
5
export const sendMessage = (url, message) => {
5
export const sendMessage = (url, message) => {
6
  return (dispatch) => {
6
  return (dispatch) => {
7
    const formData = new FormData()
7
    const formData = new FormData()
8
    formData.append('message', emojione.toShort(message))
8
    formData.append('message', emojione.toShort(message))
Línea -... Línea 9...
-
 
9
 
9
 
10
    axios
10
    axios.post(url, formData)
11
      .post(url, formData)
11
      .then(({ data: response }) => {
12
      .then(({ data: response }) => {
-
 
13
        if (!response.success) {
12
        if (!response.success) {
14
          dispatch(
-
 
15
            addNotification({ style: 'danger', msg: 'Ha ocurrido un error' })
13
          dispatch(addNotification({ style: 'danger', msg: 'Ha ocurrido un error' }))
16
          )
14
          return
17
          return
Línea 15... Línea 18...
15
        }
18
        }
16
 
19
 
17
        dispatch(setNewMessage(response.data))
20
        dispatch(setNewMessage(response.data))
18
      })
21
      })
19
      .catch((error) => {
22
      .catch((error) => {
-
 
23
        throw new Error(error)
-
 
24
      })
20
        throw Error(error.message)
25
      .catch((err) =>
-
 
26
        dispatch(
-
 
27
          addNotification({ style: 'danger', msg: new Error(err).message })
21
      })
28
        )
22
      .catch((err) => dispatch(addNotification({ style: 'danger', msg: new Error(err).message })))
29
      )
23
      .finally(() => dispatch(finishLoading()))
30
      .finally(() => dispatch(finishLoading()))
Línea 24... Línea 31...
24
  }
31
  }
25
}
32
}
26
 
33
 
-
 
34
export const getMessages = (url) => {
27
export const getMessages = (url) => {
35
  return (dispatch) => {
28
  return (dispatch) => {
36
    dispatch(startLoading())
29
    dispatch(startLoading())
37
    axios
-
 
38
      .get(url)
30
    axios.get(url)
39
      .then(({ data: response }) => {
-
 
40
        if (!response.success) {
31
      .then(({ data: response }) => {
41
          dispatch(
32
        if (!response.success) {
42
            addNotification({ style: 'danger', msg: 'Ha ocurrido un error' })
33
          dispatch(addNotification({ style: 'danger', msg: 'Ha ocurrido un error' }))
43
          )
Línea 34... Línea 44...
34
          return
44
          return
Línea 46... Línea 56...
46
}
56
}
Línea 47... Línea 57...
47
 
57
 
48
export const getMessagesByPage = (url, page = 1) => {
58
export const getMessagesByPage = (url, page = 1) => {
49
  return (dispatch) => {
59
  return (dispatch) => {
-
 
60
    dispatch(startLoading())
50
    dispatch(startLoading())
61
    axios
51
    axios.get(`${url}?page=${page}`)
62
      .get(`${url}?page=${page}`)
52
      .then(({ data: response }) => {
63
      .then(({ data: response }) => {
-
 
64
        if (!response.success) {
53
        if (!response.success) {
65
          dispatch(
-
 
66
            addNotification({ style: 'danger', msg: 'Ha ocurrido un error' })
54
          dispatch(addNotification({ style: 'danger', msg: 'Ha ocurrido un error' }))
67
          )
55
          return
68
          return
56
        }
69
        }
Línea 57... Línea 70...
57
        const updatedMessages = [...response.data.items].reverse()
70
        const updatedMessages = [...response.data.items].reverse()
Línea 66... Línea 79...
66
  }
79
  }
67
}
80
}
Línea 68... Línea 81...
68
 
81
 
69
export const setNewMessage = (newMessage) => ({
82
export const setNewMessage = (newMessage) => ({
70
  type: conversationActionTypes.SET_NEW_MESSAGE,
83
  type: conversationActionTypes.SET_NEW_MESSAGE,
71
  payload: newMessage
84
  payload: newMessage,
Línea 72... Línea 85...
72
})
85
})
73
 
86
 
74
export const updateMessages = (newMessages) => ({
87
export const updateMessages = (newMessages) => ({
75
  type: conversationActionTypes.SET_UPDATE_MESSAGES,
88
  type: conversationActionTypes.SET_UPDATE_MESSAGES,
Línea 76... Línea 89...
76
  payload: newMessages
89
  payload: newMessages,
77
})
90
})
78
 
91
 
79
export const setPage = (messages) => ({
92
export const setPage = (messages) => ({
Línea 80... Línea 93...
80
  type: conversationActionTypes.SET_MESSAGES,
93
  type: conversationActionTypes.SET_MESSAGES,
81
  payload: messages
94
  payload: messages,
82
})
95
})
83
 
96
 
Línea 84... Línea 97...
84
export const setMessages = (messages) => ({
97
export const setMessages = (messages) => ({
85
  type: conversationActionTypes.SET_MESSAGES,
98
  type: conversationActionTypes.SET_MESSAGES,
86
  payload: messages
99
  payload: messages,
Línea 87... Línea 100...
87
})
100
})
88
 
101
 
89
export const startLoading = () => ({
102
export const startLoading = () => ({