Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5338 | Rev 5925 | Ir a la última revisión | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
5334 stevensc 1
/* eslint-disable react/prop-types */
2
import React, { useState } from 'react'
3
import parse from 'html-react-parser'
4
import LikeButton from '../../chat/chat/personal-chat/like-button/LikeButton'
5
import { addNotification } from '../../redux/notification/notification.actions'
6
import { useDispatch } from 'react-redux'
7
 
8
const Message = ({ message, setResponseMessage }) => {
9
  const [isLiked, setIsLiked] = useState(false)
10
  const dispatch = useDispatch()
11
 
12
  const senderName = (message) => {
13
    if (message.type === 'group' && !message.u === 1) return message.user_name
14
  }
15
 
16
  const handleCopy = async () => {
17
    await navigator.clipboard.writeText(`${message.m}`)
5923 stevensc 18
    dispatch(
19
      addNotification({
20
        style: 'success',
21
        msg: 'Mensaje copiado en el portapapeles',
22
      })
23
    )
5334 stevensc 24
  }
25
 
26
  const likeMessage = () => setIsLiked(!isLiked)
27
 
28
  const handleResponse = (msg) => setResponseMessage(msg)
29
 
30
  const messagesContent = {
31
    text: <p>{parse(emojione.shortnameToImage(message.m))}</p>,
5336 stevensc 32
    image: <img src={message.m} alt="chat_image" />,
5923 stevensc 33
    video: <video src={message.m} preload="none" controls />,
34
    document: (
35
      <img
36
        className="pdf"
37
        src="/storage/type/default/filename/pdf.png"
38
        alt="pdf"
39
      />
40
    ),
5334 stevensc 41
  }
42
 
43
  return (
5923 stevensc 44
    <div
45
      className={`message ${
46
        message.u === 1 ? 'message_sent' : 'message_received'
47
      }`}
48
    >
49
      <div className="messageContainer">
50
        <span className="userName">{senderName(message)}</span>
51
        {messagesContent[message.mtype]}
52
        <label>
53
          {!message.not_received && (
54
            <i
55
              className="fa fa-check"
56
              style={message.seen ? { color: 'blue' } : { color: 'gray' }}
5334 stevensc 57
            />
5923 stevensc 58
          )}
59
          {message.time}
60
        </label>
61
        <span className={'message__time'}>{message.time}</span>
62
        {isLiked && (
63
          <i
64
            className="fas fa-heart"
65
            style={{
66
              color: '#0961bf',
67
              position: 'absolute',
68
              top: '87%',
69
              left: '85%',
70
            }}
71
          />
72
        )}
73
      </div>
74
      <Message.Reactions
75
        message={message}
76
        onLike={likeMessage}
77
        onResponse={handleResponse}
78
        onClipboard={handleCopy}
79
      />
80
    </div>
5334 stevensc 81
  )
82
}
83
 
84
const Reactions = ({
85
  message = {},
86
  onLike = () => false,
87
  onResponse = () => false,
5923 stevensc 88
  onClipboard = () => false,
5334 stevensc 89
}) => {
90
  const [isShow, setIsShow] = useState(false)
91
 
92
  return (
5923 stevensc 93
    <>
94
      <i className="la la-ellipsis-v icon" onClick={() => setIsShow(!isShow)} />
95
      {isShow && (
96
        <div className="display-reactions">
97
          <LikeButton onClick={onLike} />
98
          <button onClick={() => onResponse(message)}>
99
            <i className="fa fa-reply" />
100
          </button>
101
          <button onClick={() => onClipboard(message)}>
102
            <i className="fa fa-copy" />
103
          </button>
104
        </div>
105
      )}
106
    </>
5334 stevensc 107
  )
108
}
109
 
110
Message.Reactions = Reactions
111
 
112
export default Message