Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 5335 | Ir a la última revisión | | 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>,
27
    image:
28
            <div className="chat_image_container">
29
                <img src={message.m} alt="chat_image" />
30
            </div>,
31
    video:
32
            <div className="chat_image_container">
33
                <video src={message.m} preload="none" controls></video>
34
            </div>,
35
 
36
    document:
37
            <div className="chat_image_container">
38
                <img
39
                    className="pdf"
40
                    src="/storage/type/default/filename/pdf.png"
41
                    alt="pdf"
42
                />
43
            </div>
44
  }
45
 
46
  return (
47
        <div className="conversation-text">
48
            <div className="ctext-wrap">
49
                {senderName(message)}
50
                {messagesContent[message.mtype]}
51
                <div className="d-inline-flex align-items-center">
52
                    {!message.not_received && <i className={'fa fa-check text-right ellipsis '} style={message.seen ? { color: 'blue' } : { color: 'gray' }} />}
53
                    <label>{message.time}</label>
54
                </div>
55
                {isLiked &&
56
                    <i
57
                        className="fas fa-heart"
58
                        style={{ color: '#0961bf', position: 'absolute', top: '87%', left: '85%' }} />
59
                }
60
            </div>
61
            <Message.Reactions
62
                message={message}
63
                onLike={likeMessage}
64
                onResponse={handleResponse}
65
                onClipboard={handleCopy}
66
            />
67
        </div>
68
  )
69
}
70
 
71
const Reactions = ({
72
  message = {},
73
  onLike = () => false,
74
  onResponse = () => false,
75
  onClipboard = () => false
76
}) => {
77
  const [isShow, setIsShow] = useState(false)
78
 
79
  return (
80
        <>
81
            <i
82
                className="la la-ellipsis-v icon"
83
                style={{ position: 'relative' }}
84
                onClick={() => setIsShow(!isShow)}
85
            />
86
            {isShow &&
87
                <div className="display-reactions" >
88
                    <LikeButton onClick={onLike} />
89
                    <button onClick={() => onResponse(message)}>
90
                        <i className="fa fa-reply" />
91
                    </button>
92
                    <button onClick={() => onClipboard(message)}>
93
                        <i className="fa fa-copy" />
94
                    </button>
95
                </div>}
96
        </>
97
  )
98
}
99
 
100
Message.Reactions = Reactions
101
 
102
export default Message