Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1684 stevensc 1
import React, { useEffect } from 'react'
2
import { Box, styled } from '@mui/material'
1685 stevensc 3
import { Inbox } from '@mui/icons-material'
1684 stevensc 4
 
5
import useNearScreen from '@app/hooks/useNearScreen'
6
 
1685 stevensc 7
import EmptySection from '../UI/EmptySection'
8
import LoaderContainer from '../UI/LoaderContainer'
9
import Spinner from '../UI/Spinner'
1684 stevensc 10
import Message from './message'
11
 
12
const MessagesContainer = styled(Box)`
13
  gap: 0.5rem;
14
  display: flex;
15
  flex-direction: column-reverse;
16
  height: -webkit-fill-available;
17
  padding: 0.5rem 0;
18
  overflow: auto;
19
`
20
 
21
export default function MessagesList({
22
  messages = [],
23
  onPagination,
24
  onReport,
25
  scrollRef,
26
  loading
27
}) {
28
  const [isIntercepting, ref] = useNearScreen({
29
    once: false,
30
    rootMargin: '0px'
31
  })
32
 
33
  useEffect(() => {
34
    if (isIntercepting) {
35
      onPagination()
36
    }
37
  }, [isIntercepting])
38
 
39
  return (
40
    <MessagesContainer ref={scrollRef}>
1686 stevensc 41
      {!messages.length ? (
42
        <EmptySection
43
          Icon={<Inbox />}
44
          message='No hay mensajes en esta conversación'
45
          align='center'
46
        />
47
      ) : (
48
        messages.map((message) => (
1699 stevensc 49
          <Message
50
            key={message.id}
51
            message={message}
52
            reportUrl={message.url_abuse_report}
53
            onReport={onReport}
54
          />
1686 stevensc 55
        ))
56
      )}
1684 stevensc 57
 
1685 stevensc 58
      <p ref={ref}>.</p>
59
      {loading ? (
60
        <LoaderContainer>
61
          <Spinner />
62
        </LoaderContainer>
63
      ) : null}
1684 stevensc 64
    </MessagesContainer>
65
  )
66
}