Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 5307 Rev 5311
Línea 1... Línea 1...
1
import { axios } from '../../utils'
1
import { axios } from '../../utils'
2
import { addNotification } from '../notification/notification.actions'
2
import { addNotification } from '../notification/notification.actions'
3
import { conversationActionTypes } from './conversation.types'
3
import { conversationActionTypes } from './conversation.types'
Línea 4... Línea 4...
4
 
4
 
5
export const sendMessage = async (url, message) => {
5
export const setNewMessage = (newMessage) => ({
6
  return (dispatch) => {
6
  type: conversationActionTypes.SET_NEW_MESSAGE,
-
 
7
  payload: newMessage
Línea 7... Línea 8...
7
    dispatch(startLoading())
8
})
8
 
9
 
-
 
10
export const setMessages = (unreadMessages) => ({
-
 
11
  type: conversationActionTypes.SET_MESSAGES,
Línea -... Línea 12...
-
 
12
  payload: unreadMessages
-
 
13
})
-
 
14
 
-
 
15
export const startLoading = () => ({
-
 
16
  type: conversationActionTypes.START_LOADING
-
 
17
})
-
 
18
 
-
 
19
export const finishLoading = () => ({
-
 
20
  type: conversationActionTypes.FINISH_LOADING
-
 
21
})
-
 
22
 
9
    const formData = new FormData()
23
export const getMessages = async (url) => {
10
    formData.append('message', emojione.toShort(message))
24
  return (dispatch) => {
11
 
25
    dispatch(startLoading())
12
    axios.post(url, formData)
26
    axios.get(url)
13
      .then(({ data: response }) => {
27
      .then(({ data: response }) => {
14
        if (!response.success) {
28
        if (!response.success) {
-
 
29
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
Línea 15... Línea 30...
15
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
30
          return
16
          return
31
        }
17
        }
32
        const updatedMessages = [...response.data.items].reverse()
18
 
33
 
19
        dispatch(setNewMessage(response.data))
34
        dispatch(setMessages(updatedMessages))
20
      })
35
      })
21
      .catch((err) => {
36
      .catch((err) => {
22
        const errorMessage = new Error(err).message
37
        const errorMessage = new Error(err).message
23
        dispatch(addNotification({ style: 'danger', message: errorMessage }))
38
        dispatch(addNotification({ style: 'danger', message: errorMessage }))
Línea 24... Línea 39...
24
      })
39
      })
25
      .finally(() => dispatch(finishLoading()))
40
      .finally(() => dispatch(finishLoading()))
26
  }
41
  }
-
 
42
}
-
 
43
 
-
 
44
export const sendMessage = async (url, message) => {
-
 
45
  return (dispatch) => {
27
}
46
    dispatch(startLoading())
28
 
47
 
29
export const getMessages = async (url) => {
48
    const formData = new FormData()
30
  return (dispatch) => {
49
    formData.append('message', emojione.toShort(message))
31
    dispatch(startLoading())
50
 
32
    axios.get(url)
51
    axios.post(url, formData)
33
      .then(({ data: response }) => {
-
 
Línea 34... Línea 52...
34
        if (!response.success) {
52
      .then(({ data: response }) => {
35
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
53
        if (!response.success) {
36
          return
54
          dispatch(addNotification({ style: 'danger', message: 'Ha ocurrido un error' }))
37
        }
55
          return
38
        const updatedMessages = [...response.data.items].reverse()
56
        }
39
 
57
 
40
        dispatch(setMessages(updatedMessages))
58
        dispatch(setNewMessage(response.data))
41
      })
59
      })
42
      .catch((err) => {
60
      .catch((err) => {
43
        const errorMessage = new Error(err).message
-
 
44
        dispatch(addNotification({ style: 'danger', message: errorMessage }))
-
 
45
      })
-
 
46
      .finally(() => dispatch(finishLoading()))
-
 
47
  }
-
 
48
}
-
 
49
 
-
 
50
export const setNewMessage = (newMessage) => ({
-
 
51
  type: conversationActionTypes.SET_NEW_MESSAGE,
-
 
52
  payload: newMessage
-
 
53
})
-
 
54
 
-
 
55
export const setMessages = (unreadMessages) => ({
-
 
56
  type: conversationActionTypes.SET_MESSAGES,
-
 
57
  payload: unreadMessages
-
 
58
})
-
 
59
 
-
 
60
export const startLoading = () => ({
-