Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 6981 Rev 6984
Línea 31... Línea 31...
31
  const toggleConversationModal = () => {
31
  const toggleConversationModal = () => {
32
    setShowConversationModal(!showConversationModal)
32
    setShowConversationModal(!showConversationModal)
33
  }
33
  }
Línea 34... Línea 34...
34
 
34
 
-
 
35
  const getConversations = async () => {
35
  const getConversations = async () => {
36
    setLoading(true)
36
    try {
37
    axios
-
 
38
      .get(window.location.href)
37
      setLoading(true)
39
      .then((response) => {
-
 
40
        const { data, success } = response.data
-
 
41
 
-
 
42
        if (!success) {
-
 
43
          return
-
 
44
        }
38
      const { data } = await axios.get(window.location.href)
45
 
-
 
46
        const resConversations = data
-
 
47
 
-
 
48
        const newConversations = resConversations.reduce(
-
 
49
          (acum, conversation) => {
-
 
50
            const messageIndex = conversations.findIndex(
-
 
51
              ({ uuid }) => uuid === conversation.id
-
 
52
            )
-
 
53
 
-
 
54
            if (messageIndex === -1) {
-
 
55
              acum = [...acum, conversation]
-
 
56
            }
-
 
57
 
-
 
58
            return acum
-
 
59
          },
-
 
60
          []
-
 
61
        )
-
 
62
 
-
 
63
        if (!newConversations.length) {
-
 
64
          return
-
 
65
        }
-
 
66
 
-
 
67
        setConversations((prevConversations) => [
-
 
68
          ...newConversations,
-
 
69
          ...prevConversations,
-
 
70
        ])
39
      if (data.success) setConversations(data.data)
71
      })
40
    } catch (error) {
72
      .catch((error) => {
-
 
73
        const errorMessage = new Error(error)
41
      const errorMessage = new Error(error)
74
        dispatch(
42
      dispatch(addNotification({ style: 'danger', msg: errorMessage.message }))
75
          addNotification({ style: 'danger', msg: errorMessage.message })
43
    } finally {
-
 
44
      setLoading(false)
76
        )
-
 
77
      })
45
    }
78
      .finally(() => setLoading(false))
Línea 46... Línea 79...
46
  }
79
  }
47
 
80
 
48
  const changeConversation = (conversation) => {
81
  const changeConversation = (conversation) => {
Línea 69... Línea 102...
69
      clearTimeout(messagesInterval)
102
      clearTimeout(messagesInterval)
70
    }
103
    }
71
  }, [loading])
104
  }, [loading])
Línea 72... Línea 105...
72
 
105
 
73
  useEffect(() => {
-
 
74
    console.log(uuid)
-
 
75
 
106
  useEffect(() => {
76
    if (uuid) {
107
    if (uuid) {
77
      const conversation = conversations.find((c) => c.uuid === uuid)
108
      const conversation = conversations.find((c) => c.uuid === uuid)
78
      conversation && setCurrentConversation(conversation)
109
      conversation && setCurrentConversation(conversation)
79
    }
110
    }