Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5336 | Rev 5923 | 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 (
5338 stevensc 33
        <div className={`conversation-text ${message.u === 1 && '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>
5338 stevensc 41
                {isLiked && <i className="fas fa-heart" style={{ color: '#0961bf', position: 'absolute', top: '87%', left: '85%' }} />}
5334 stevensc 42
            </div>
43
            <Message.Reactions
44
                message={message}
45
                onLike={likeMessage}
46
                onResponse={handleResponse}
47
                onClipboard={handleCopy}
48
            />
49
        </div>
50
  )
51
}
52
 
53
const Reactions = ({
54
  message = {},
55
  onLike = () => false,
56
  onResponse = () => false,
57
  onClipboard = () => false
58
}) => {
59
  const [isShow, setIsShow] = useState(false)
60
 
61
  return (
62
        <>
5338 stevensc 63
            <i className="la la-ellipsis-v icon" onClick={() => setIsShow(!isShow)}/>
5334 stevensc 64
            {isShow &&
65
                <div className="display-reactions" >
66
                    <LikeButton onClick={onLike} />
67
                    <button onClick={() => onResponse(message)}>
68
                        <i className="fa fa-reply" />
69
                    </button>
70
                    <button onClick={() => onClipboard(message)}>
71
                        <i className="fa fa-copy" />
72
                    </button>
73
                </div>}
74
        </>
75
  )
76
}
77
 
78
Message.Reactions = Reactions
79
 
80
export default Message