Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 5206 Rev 5307
Línea 12... Línea 12...
12
import FormErrorFeedback from '../../../shared/form-error-feedback/FormErrorFeedback'
12
import FormErrorFeedback from '../../../shared/form-error-feedback/FormErrorFeedback'
13
import 'react-datetime/css/react-datetime.css'
13
import 'react-datetime/css/react-datetime.css'
14
import Datetime from 'react-datetime'
14
import Datetime from 'react-datetime'
15
import { addNotification } from '../../../redux/notification/notification.actions'
15
import { addNotification } from '../../../redux/notification/notification.actions'
16
import Spinner from '../../../shared/loading-spinner/Spinner'
16
import Spinner from '../../../shared/loading-spinner/Spinner'
17
import { useDispatch } from 'react-redux'
17
import { useDispatch, useSelector } from 'react-redux'
18
import SearchIcon from '@mui/icons-material/Search'
18
import SearchIcon from '@mui/icons-material/Search'
19
import EmptySection from '../../../shared/empty-section/EmptySection'
19
import EmptySection from '../../../shared/empty-section/EmptySection'
-
 
20
import { finishLoading, getMessages, startLoading } from '../../../redux/conversation/conversation.actions'
Línea 20... Línea 21...
20
 
21
 
21
const StyledChatHead = styled.div`
22
const StyledChatHead = styled.div`
22
  .notify {
23
  .notify {
23
    animation: notify 2s infinite;
24
    animation: notify 2s infinite;
Línea 96... Línea 97...
96
    url_get_contact_group_list,
97
    url_get_contact_group_list,
97
    url_get_contacts_availables_for_group,
98
    url_get_contacts_availables_for_group,
98
    url_zoom
99
    url_zoom
99
  } = entity
100
  } = entity
Línea -... Línea 101...
-
 
101
 
-
 
102
  const { messages, currentPage, lastPage, loading } = useSelector()
-
 
103
  const dispatch = useDispatch()
100
 
104
 
101
  // states
-
 
102
  const [messages, setMessages] = useState([])
105
  // states
103
  const [responseMessage, setResponseMessage] = useState(null)
-
 
104
  const [oldMessages, setOldMessages] = useState([])
-
 
105
  const [currentPage, setCurrentPage] = useState(1)
-
 
106
  const [pages, setPages] = useState(1)
106
  const [responseMessage, setResponseMessage] = useState(null)
107
  const [showOptions, setShowOptions] = useState(false)
107
  const [showOptions, setShowOptions] = useState(false)
-
 
108
  const [optionTab, setOptionTab] = useState('default')
108
  const [optionTab, setOptionTab] = useState('default')
109
 
109
  const [availableContactsToAdd, setAvailableContactsToAdd] = useState([])
110
  const [availableContactsToAdd, setAvailableContactsToAdd] = useState([])
-
 
111
  const [groupContactsList, setGroupContactsList] = useState([])
110
  const [groupContactsList, setGroupContactsList] = useState([])
112
 
111
  const [confirmModalShow, setConfirmModalShow] = useState(false)
113
  const [confirmModalShow, setConfirmModalShow] = useState(false)
112
  const [showEmojiTab, setShowEmojiTab] = useState(false)
114
  const [showEmojiTab, setShowEmojiTab] = useState(false)
113
  const [shareFileModalShow, setShareFileModalShow] = useState(false)
115
  const [shareFileModalShow, setShareFileModalShow] = useState(false)
114
  const [showConferenceModal, setShowConferenceModal] = useState(false)
-
 
-
 
116
  const [showConferenceModal, setShowConferenceModal] = useState(false)
115
  const [loading, setLoading] = useState(false)
117
 
Línea 116... Línea 118...
116
  const [search, setSearch] = useState('')
118
  const [search, setSearch] = useState('')
Línea 117... Línea 119...
117
 
119
 
Línea 136... Línea 138...
136
    onRead(entity)
138
    onRead(entity)
137
    onMinimize(entity)
139
    onMinimize(entity)
138
  }
140
  }
Línea 139... Línea 141...
139
 
141
 
140
  const handleGetMessages = async () => {
142
  const handleGetMessages = async () => {
141
    setLoading(true)
143
    dispatch(startLoading())
142
    const response = await axios.get(url_get_all_messages)
-
 
143
    const resData = response.data
-
 
144
    if (!resData.success) {
-
 
145
      return ('ha ocurrido un error', resData)
-
 
146
    }
-
 
147
    const updatedMessages = [...resData.data.items].reverse()
-
 
148
    const newMessages = updatedMessages.reduce((acum, updatedMessage) => {
-
 
149
      if (messages.findIndex((message) => message.id === updatedMessage.id) === -1) {
-
 
150
        acum = [...acum, updatedMessage]
-
 
151
      }
-
 
152
      return acum
-
 
153
    }, [])
-
 
154
 
-
 
155
    if (newMessages.length > 0) {
-
 
156
      setMessages([...messages, ...newMessages])
144
    dispatch(getMessages(url_get_all_messages))
157
      setLoading(false)
-
 
158
      setPages(resData.data.pages)
145
    dispatch(finishLoading())
159
      scrollToBottom()
-
 
160
    } else {
-
 
161
      setMessages([...updatedMessages])
-
 
162
      setLoading(false)
-
 
163
    }
146
    scrollToBottom()
Línea 164... Línea 147...
164
  }
147
  }
165
 
148
 
166
  const handleLoadMore = async () => {
149
  const handleLoadMore = async () => {
167
    await axios.get(`${url_get_all_messages}?page=${currentPage}`)
150
    await axios.get(`${url_get_all_messages}?page=${currentPage}`)
168
      .then((response) => {
151
      .then((response) => {
169
        const resData = response.data
152
        const resData = response.data
170
        if (resData.success) {
153
        if (resData.success) {
171
          if (resData.data.page > 1) {
154
          if (resData.data.page > 1) {
172
            const updatedOldMessages = [...resData.data.items].reverse()
155
            const updatedOldMessages = [...resData.data.items].reverse()
173
            setOldMessages([...updatedOldMessages, ...oldMessages])
156
            // setOldMessages([...updatedOldMessages, ...oldMessages])
174
            /* scrollDownBy(100); */
157
            /* scrollDownBy(100); */
175
          }
158
          }
176
        }
159
        }
Línea 192... Línea 175...
192
 
175
 
193
          online
176
          online
194
            ? newMessage = { ...newMessage, not_received: false }
177
            ? newMessage = { ...newMessage, not_received: false }
Línea 195... Línea 178...
195
            : newMessage = { ...newMessage, not_received: true }
178
            : newMessage = { ...newMessage, not_received: true }
196
 
179
 
197
          setMessages([...messages, newMessage])
180
          // setMessages([...messages, newMessage])
198
        }
181
        }
199
      })
182
      })
200
      e.target.value = ''
183
      e.target.value = ''
Línea 237... Línea 220...
237
  }
220
  }
Línea 238... Línea 221...
238
 
221
 
239
  const handleObserver = (entities) => {
222
  const handleObserver = (entities) => {
240
    const target = entities[0]
223
    const target = entities[0]
241
    if (target.isIntersecting) {
224
    if (target.isIntersecting) {
242
      setCurrentPage((prevState) => prevState + 1)
225
      // setCurrentPage((prevState) => prevState + 1)
243
    }
226
    }
Línea 244... Línea 227...
244
  }
227
  }
245
 
228
 
Línea 341... Línea 324...
341
 
324
 
Línea 342... Línea 325...
342
  const displayConferenceModal = () => setShowConferenceModal(!showConferenceModal)
325
  const displayConferenceModal = () => setShowConferenceModal(!showConferenceModal)
343
 
326
 
344
  const messagesRender = () => {
327
  const messagesRender = () => {
345
    return (
328
    return (
346
      <React.Fragment>
-
 
347
        {currentPage < pages ? <li ref={loader}>Cargando...</li> : ''}
-
 
348
        {oldMessages.map((oldMessage) => (
-
 
349
          <MessageTemplate time={oldMessage.time} key={oldMessage.id} message={oldMessage} />
329
      <>
350
        ))}
-
 
351
        {messages.map((message, i) => {
-
 
352
          const currentTime = message.time
-
 
353
          const prevMessage = messages[i - 1]
-
 
354
 
-
 
355
          const dailys = ['mes', 'meses', 'semana', 'semanas', 'dia', 'dias', 'año', 'años']
-
 
356
          // const date = new Date(Date.now()).toLocaleDateString()
-
 
357
 
-
 
358
          if (prevMessage !== undefined) {
-
 
359
            const prevTime = messages[i - 1].time
-
 
360
 
-
 
361
            if (prevTime !== currentTime && dailys.includes(prevTime.split(' ')[1])) {
-
 
362
              return <>
330
        {currentPage < lastPage && <li ref={loader}>Cargando...</li>}
363
                {/* <h2 className="text-center date-chat">{date}</h2> */}
-
 
364
                <MessageTemplate
-
 
365
                  key={message.id}
-
 
366
                  message={message}
-
 
367
                  time={message.time}
-
 
368
                  setResponseMessage={handleResponseMessage}
-
 
369
                  responseMessage={responseMessage}
-
 
370
                />
-
 
371
              </>
-
 
372
            }
-
 
373
          }
-
 
374
 
331
        {messages.map((message, i) => (
375
          return <MessageTemplate
332
          <MessageTemplate
376
            key={message.id}
333
            key={message.id}
377
            message={message}
334
            message={message}
378
            time={message.time}
335
            time={message.time}
379
            setResponseMessage={handleResponseMessage}
336
            setResponseMessage={handleResponseMessage}
380
            responseMessage={responseMessage}
337
            responseMessage={responseMessage}
381
          />
338
          />
382
        })}
339
        ))}
383
      </React.Fragment>
340
      </>
Línea 384... Línea 341...
384
    )
341
    )
385
  }
342
  }