Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5335 | Rev 5338 | 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}`)
18
    dispatch(addNotification({ style: 'success', msg: 'Mensaje copiado en el portapapeles' }))
19
  }
20
 
21
  const likeMessage = () => setIsLiked(!isLiked)
22
 
23
  const handleResponse = (msg) => setResponseMessage(msg)
24
 
25
  const messagesContent = {
26
    text: <p>{parse(emojione.shortnameToImage(message.m))}</p>,
5336 stevensc 27
    image: <img src={message.m} alt="chat_image" />,
28
    video: <video src={message.m} preload="none" controls></video>,
29
    document: <img className="pdf" src="/storage/type/default/filename/pdf.png" alt="pdf"/>
5334 stevensc 30
  }
31
 
32
  return (
5336 stevensc 33
        <div className={`conversation-text ${message.u === 2 && 'odd'}`}>
5334 stevensc 34
            <div className="ctext-wrap">
35
                {senderName(message)}
36
                {messagesContent[message.mtype]}
5336 stevensc 37
                <label>
38
                    {!message.not_received && <i className='fa fa-check' style={message.seen ? { color: 'blue' } : { color: 'gray' }} />}
39
                    {message.time}
40
                </label>
5334 stevensc 41
                {isLiked &&
42
                    <i
43
                        className="fas fa-heart"
44
                        style={{ color: '#0961bf', position: 'absolute', top: '87%', left: '85%' }} />
45
                }
46
            </div>
47
            <Message.Reactions
48
                message={message}
49
                onLike={likeMessage}
50
                onResponse={handleResponse}
51
                onClipboard={handleCopy}
52
            />
53
        </div>
54
  )
55
}
56
 
57
const Reactions = ({
58
  message = {},
59
  onLike = () => false,
60
  onResponse = () => false,
61
  onClipboard = () => false
62
}) => {
63
  const [isShow, setIsShow] = useState(false)
64
 
65
  return (
66
        <>
67
            <i
68
                className="la la-ellipsis-v icon"
69
                style={{ position: 'relative' }}
70
                onClick={() => setIsShow(!isShow)}
71
            />
72
            {isShow &&
73
                <div className="display-reactions" >
74
                    <LikeButton onClick={onLike} />
75
                    <button onClick={() => onResponse(message)}>
76
                        <i className="fa fa-reply" />
77
                    </button>
78
                    <button onClick={() => onClipboard(message)}>
79
                        <i className="fa fa-copy" />
80
                    </button>
81
                </div>}
82
        </>
83
  )
84
}
85
 
86
Message.Reactions = Reactions
87
 
88
export default Message