Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 5320 Rev 5331
Línea 8... Línea 8...
8
    formData.append('message', emojione.toShort(message))
8
    formData.append('message', emojione.toShort(message))
Línea 9... Línea 9...
9
 
9
 
10
    axios.post(url, formData)
10
    axios.post(url, formData)
11
      .then(({ data: response }) => {
11
      .then(({ data: response }) => {
12
        if (!response.success) {
12
        if (!response.success) {
13
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
13
          dispatch(addNotification({ style: 'danger', msg: 'Ha ocurrido un error' }))
14
          return
14
          return
Línea 15... Línea 15...
15
        }
15
        }
16
 
16
 
17
        dispatch(setNewMessage(response.data))
17
        dispatch(setNewMessage(response.data))
18
      })
18
      })
19
      .catch((error) => {
19
      .catch((error) => {
20
        throw Error(error.message)
20
        throw Error(error.message)
21
      })
21
      })
22
      .catch((err) => dispatch(addNotification({ style: 'danger', message: new Error(err).message })))
22
      .catch((err) => dispatch(addNotification({ style: 'danger', msg: new Error(err).message })))
23
      .finally(() => dispatch(finishLoading()))
23
      .finally(() => dispatch(finishLoading()))
Línea 24... Línea 24...
24
  }
24
  }
25
}
25
}
26
 
26
 
27
export const getMessages = (url) => {
27
export const getMessages = (url) => {
28
  return (dispatch) => {
28
  return (dispatch) => {
29
    dispatch(startLoading())
29
    dispatch(startLoading())
30
    axios.get(url)
30
    axios.get(url)
31
      .then(({ data: response }) => {
31
      .then(({ data: response }) => {
32
        if (!response.success) {
32
        if (!response.success) {
33
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
33
          dispatch(addNotification({ style: 'danger', msg: 'Ha ocurrido un error' }))
Línea 34... Línea 34...
34
          return
34
          return
35
        }
35
        }
36
        const updatedMessages = [...response.data.items].reverse()
36
        const updatedMessages = [...response.data.items].reverse()
37
 
37
 
38
        dispatch(setMessages(updatedMessages))
38
        dispatch(setMessages(updatedMessages))
39
      })
39
      })
40
      .catch((err) => {
40
      .catch((err) => {
41
        const errorMessage = new Error(err).message
41
        const errorMessage = new Error(err).message
42
        dispatch(addNotification({ style: 'danger', message: errorMessage }))
42
        dispatch(addNotification({ style: 'danger', msg: errorMessage }))
Línea 49... Línea 49...
49
  return (dispatch) => {
49
  return (dispatch) => {
50
    dispatch(startLoading())
50
    dispatch(startLoading())
51
    axios.get(`${url}?page=${page}`)
51
    axios.get(`${url}?page=${page}`)
52
      .then(({ data: response }) => {
52
      .then(({ data: response }) => {
53
        if (!response.success) {
53
        if (!response.success) {
54
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
54
          dispatch(addNotification({ style: 'danger', msg: 'Ha ocurrido un error' }))
55
          return
55
          return
56
        }
56
        }
57
        const updatedMessages = [...response.data.items].reverse()
57
        const updatedMessages = [...response.data.items].reverse()
Línea 58... Línea 58...
58
 
58
 
59
        dispatch(setMessages(updatedMessages))
59
        dispatch(setMessages(updatedMessages))
60
      })
60
      })
61
      .catch((err) => {
61
      .catch((err) => {
62
        const errorMessage = new Error(err).message
62
        const errorMessage = new Error(err).message
63
        dispatch(addNotification({ style: 'danger', message: errorMessage }))
63
        dispatch(addNotification({ style: 'danger', msg: errorMessage }))
64
      })
64
      })
65
      .finally(() => dispatch(finishLoading()))
65
      .finally(() => dispatch(finishLoading()))
66
  }
66
  }
Línea 74... Línea 74...
74
export const updateMessages = (newMessages) => ({
74
export const updateMessages = (newMessages) => ({
75
  type: conversationActionTypes.SET_UPDATE_MESSAGES,
75
  type: conversationActionTypes.SET_UPDATE_MESSAGES,
76
  payload: newMessages
76
  payload: newMessages
77
})
77
})
Línea -... Línea 78...
-
 
78
 
-
 
79
export const setPage = (messages) => ({
-
 
80
  type: conversationActionTypes.SET_MESSAGES,
-
 
81
  payload: messages
-
 
82
})
78
 
83
 
79
export const setMessages = (messages) => ({
84
export const setMessages = (messages) => ({
80
  type: conversationActionTypes.SET_MESSAGES,
85
  type: conversationActionTypes.SET_MESSAGES,
81
  payload: messages
86
  payload: messages