Proyectos de Subversion LeadersLinked - SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1684 stevensc 1
import React, { useEffect, useState } from 'react'
2
import { Box, styled } from '@mui/material'
3
import { Check } from '@mui/icons-material'
4
import parse from 'html-react-parser'
5
 
6
import Options from '../UI/Option'
7
 
8
const MessageTemplate = styled(Box)`
9
  box-shadow: var(--light-shadow);
10
  display: inline-flex;
11
  flex-direction: column;
12
  gap: 0.5rem;
13
  margin-bottom: 0.5rem;
14
  max-width: 70%;
15
  min-width: 4rem;
16
  padding: 0.5rem;
17
  position: relative;
18
  & > p {
19
    color: var(--chat-color);
20
    max-width: 100%;
21
    overflow: hidden;
22
    text-overflow: ellipsis;
23
    word-break: break-word;
24
  }
25
  & > img,
26
  & > video {
27
    max-width: 250px;
28
    max-height: 250px;
29
    object-fit: contain;
30
  }
31
  &:first-child {
32
    margin-top: 0.5rem;
33
  }
34
  .time {
35
    color: var(--subtitle-color);
36
    font-size: 0.8rem;
37
  }
38
  .emojione {
39
    width: 1rem;
40
    height: 1rem;
41
  }
42
`
43
 
44
export default function Message({ message, onReport }) {
45
  const [options, setOptions] = useState([])
46
  const {
47
    u,
48
    side,
49
    type,
50
    user_name,
51
    filename,
52
    m,
53
    url_abuse_report,
54
    mtype,
55
    not_received,
56
    seen,
57
    date,
58
    time,
59
    id
60
  } = message
61
  const isSend = u === 1 || side === 'left'
62
  const showName = type === 'group' && !u === 1
63
 
64
  const messagesContent = {
65
    text: <p>{parse(emojione.shortnameToImage(m || message))}</p>,
66
    image: <img src={m || filename} alt='chat_image' />,
67
    video: <video src={m || filename} preload='none' controls />,
68
    document: (
69
      <a href={m || filename} download>
70
        <img className='pdf' src='/images/extension/pdf.png' alt='pdf' />
71
      </a>
72
    )
73
  }
74
 
75
  useEffect(() => {
76
    if (url_abuse_report) {
77
      const reportOption = {
78
        action: () => onReport({ url: url_abuse_report, id }),
79
        label: 'Reportar'
80
      }
81
      setOptions([...options, reportOption])
82
    }
83
  }, [message])
84
 
85
  return (
86
    <>
87
      {showName ? <span className='user_name'>{user_name}</span> : null}
88
      <MessageTemplate
89
        sx={
90
          isSend
91
            ? {
92
                alignSelf: 'flex-start',
93
                backgroundColor: 'var(--chat-received)',
94
                borderRadius: '0 10px 10px 10px',
95
                marginLeft: '0.5rem'
96
              }
97
            : {
98
                alignSelf: 'flex-end',
99
                backgroundColor: '#eee',
100
                borderRadius: '10px 0px 10px 10px',
101
                marginRight: '0.5rem',
102
                color: '#393939'
103
              }
104
        }
105
      >
106
        {messagesContent[mtype || type]}
107
 
108
        <small className='time'>
109
          <Check
110
            sx={{
111
              color: seen ? 'blue' : 'gray',
112
              display: not_received ? 'none' : 'flex'
113
            }}
114
          />
115
          {time ?? date}
116
        </small>
117
 
118
        <Options options={options} right='-2.5rem' />
119
      </MessageTemplate>
120
    </>
121
  )
122
}