Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 5329 Rev 5331
Línea 3... Línea 3...
3
import React, { useEffect, useRef, useState } from 'react'
3
import React, { useEffect, useRef, useState } from 'react'
4
import { axios } from '../../../utils'
4
import { axios } from '../../../utils'
5
import { Modal } from 'react-bootstrap'
5
import { Modal } from 'react-bootstrap'
6
import { useForm } from 'react-hook-form'
6
import { useForm } from 'react-hook-form'
7
import { addNotification } from '../../../redux/notification/notification.actions'
7
import { addNotification } from '../../../redux/notification/notification.actions'
8
import { getMessages } from '../../../redux/conversation/conversation.actions'
-
 
9
import { useDispatch, useSelector } from 'react-redux'
8
import { useDispatch } from 'react-redux'
10
import styled from 'styled-components'
9
import styled from 'styled-components'
11
import Datetime from 'react-datetime'
10
import Datetime from 'react-datetime'
12
import SearchIcon from '@mui/icons-material/Search'
11
import SearchIcon from '@mui/icons-material/Search'
13
import Emojione from './emojione/Emojione'
12
import Emojione from './emojione/Emojione'
14
import SendFileModal from './send-file-modal/SendFileModal'
13
import SendFileModal from './send-file-modal/SendFileModal'
Línea 86... Línea 85...
86
    url_get_contact_group_list,
85
    url_get_contact_group_list,
87
    url_get_contacts_availables_for_group,
86
    url_get_contacts_availables_for_group,
88
    url_zoom
87
    url_zoom
89
  } = entity
88
  } = entity
Línea 90... Línea -...
90
 
-
 
91
  const { messages, currentPage, lastPage, loading } = useSelector((state) => state.conversation)
-
 
92
  const dispatch = useDispatch()
-
 
93
 
89
 
Línea 94... Línea 90...
94
  const [optionTab, setOptionTab] = useState(OPTIONS.INITIAL)
90
  const [optionTab, setOptionTab] = useState(OPTIONS.INITIAL)
95
 
91
 
Línea 101... Línea 97...
101
  const [shareFileModalShow, setShareFileModalShow] = useState(false)
97
  const [shareFileModalShow, setShareFileModalShow] = useState(false)
102
  const [showConferenceModal, setShowConferenceModal] = useState(false)
98
  const [showConferenceModal, setShowConferenceModal] = useState(false)
Línea 103... Línea 99...
103
 
99
 
Línea -... Línea 100...
-
 
100
  const [search, setSearch] = useState('')
-
 
101
 
-
 
102
  const [messages, setMessages] = useState([])
-
 
103
  const [oldMessages, setOldMessages] = useState([])
-
 
104
  const [currentPage, setCurrentPage] = useState(1)
-
 
105
  const [lastPage, setLastPage] = useState(1)
-
 
106
 
104
  const [search, setSearch] = useState('')
107
  const [loading, setLoading] = useState(false)
Línea 105... Línea 108...
105
 
108
 
106
  const filtredGroupList = groupContactsList.filter((conversation) => conversation.name.toLowerCase().includes(search.toLowerCase()))
109
  const filtredGroupList = groupContactsList.filter((conversation) => conversation.name.toLowerCase().includes(search.toLowerCase()))
107
 
110
 
Línea 115... Línea 118...
115
    onRead(entity)
118
    onRead(entity)
116
    onMinimize(entity)
119
    onMinimize(entity)
117
  }
120
  }
Línea 118... Línea 121...
118
 
121
 
-
 
122
  const handleGetMessages = async () => {
119
  const handleGetMessages = async () => {
123
    setLoading(true)
-
 
124
    const response = await axios.get(url_get_all_messages)
-
 
125
    const resData = response.data
-
 
126
    if (!resData.success) {
-
 
127
      return ('ha ocurrido un error', resData)
-
 
128
    }
-
 
129
    const updatedMessages = [...resData.data.items].reverse()
-
 
130
    const newMessages = updatedMessages.reduce((acum, updatedMessage) => {
-
 
131
      if (messages.findIndex((message) => message.id === updatedMessage.id) === -1) {
-
 
132
        acum = [...acum, updatedMessage]
-
 
133
      }
-
 
134
      return acum
-
 
135
    }, [])
-
 
136
 
-
 
137
    if (newMessages.length > 0) {
-
 
138
      setMessages([...messages, ...newMessages])
-
 
139
      setLoading(false)
120
    dispatch(getMessages(url_get_all_messages))
140
      setLastPage(resData.data.pages)
-
 
141
      scrollToBottom()
-
 
142
    } else {
-
 
143
      setMessages([...updatedMessages])
-
 
144
      setLoading(false)
121
    scrollToBottom()
145
    }
Línea 122... Línea 146...
122
  }
146
  }
123
 
147
 
124
  const handleLoadMore = async () => {
148
  const handleLoadMore = async () => {
125
    await axios.get(`${url_get_all_messages}?page=${currentPage}`)
149
    await axios.get(`${url_get_all_messages}?page=${currentPage}`)
126
      .then((response) => {
150
      .then((response) => {
127
        const resData = response.data
151
        const resData = response.data
128
        if (resData.success) {
152
        if (resData.success) {
129
          if (resData.data.page > 1) {
153
          if (resData.data.page > 1) {
130
            const updatedOldMessages = [...resData.data.items].reverse()
154
            const updatedOldMessages = [...resData.data.items].reverse()
131
            // setOldMessages([...updatedOldMessages, ...oldMessages])
155
            setOldMessages([...updatedOldMessages, ...oldMessages])
132
            /* scrollDownBy(100); */
156
            /* scrollDownBy(100); */
133
          }
157
          }
134
        }
158
        }
Línea 191... Línea 215...
191
  }
215
  }
Línea 192... Línea 216...
192
 
216
 
193
  const handleObserver = (entities) => {
217
  const handleObserver = (entities) => {
194
    const target = entities[0]
218
    const target = entities[0]
195
    if (target.isIntersecting) {
219
    if (target.isIntersecting) {
196
      // setCurrentPage((prevState) => prevState + 1)
220
      setCurrentPage((prevState) => prevState + 1)
197
    }
221
    }
Línea 198... Línea 222...
198
  }
222
  }
199
 
223
 
Línea 410... Línea 434...
410
          : <div className="addPersonToGroupTab__person">{CHAT_LABELS.NOT_CONTACTS}</div>
434
          : <div className="addPersonToGroupTab__person">{CHAT_LABELS.NOT_CONTACTS}</div>
411
        }
435
        }
412
      </>
436
      </>
413
  }
437
  }
Línea 414... Línea 438...
414
 
438
 
415
  // useEffect(() => {
439
  useEffect(() => {
416
  //   setMessages([...oldMessages, ...newMessages]);
440
    setMessages([...oldMessages, ...messages])
Línea 417... Línea 441...
417
  // }, [newMessages, oldMessages]);
441
  }, [oldMessages])
418
 
442
 
419
  // getMessageOnMaximize and subscribe to infinite Loader
443
  // getMessageOnMaximize and subscribe to infinite Loader
420
  useEffect(async () => {
444
  useEffect(async () => {