Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev Autor Línea Nro. Línea
1191 stevensc 1
import React, { useState } from "react";
1 www 2
import parse from "html-react-parser";
3
import styled from "styled-components";
1191 stevensc 4
import LikeButton from "../like-button/LikeButton";
1332 stevensc 5
import { addNotification } from "../../../../redux/notification/notification.actions";
6
import { useDispatch } from "react-redux";
1 www 7
 
8
const StyledChatImgMessage = styled.div`
9
  display: flex;
10
  justify-content: center;
11
  align-items: center;
12
  position: initial !important;
13
  transform: initial !important;
14
  .chat_image_container {
15
    video {
1305 stevensc 16
      width: 100%;
1 www 17
      outline: none;
18
    }
19
    img {
20
      width: 150px;
21
      max-height: 200px;
22
    }
23
    .pdf {
24
      width: 40px;
25
    }
26
  }
27
  .chat_image__download_button {
28
    margin-left: 0.5rem;
29
    .fa {
2762 stevensc 30
      font-size: 1rem;
31
      color: gray;
1 www 32
    }
33
  }
34
`;
35
 
1305 stevensc 36
const ResponseMessageContainer = styled.div`
37
  display: flex;
38
  flex-direction: column;
39
  text-align: center;
40
  gap: 10px;
1306 stevensc 41
  align-items: ${props => props.isRight ? 'flex-end' : 'flex-start'};
1305 stevensc 42
`
43
 
2181 stevensc 44
const MessageTemplate = ({ message, setResponseMessage, responseMessage }) => {
1191 stevensc 45
 
46
  const [isShow, setIsShow] = useState(false);
1198 stevensc 47
  const [isLiked, setIsLiked] = useState(false);
1332 stevensc 48
  const dispatch = useDispatch()
1198 stevensc 49
 
1 www 50
  const senderName = (message) => {
51
    if (message.type === "group") {
52
      return message.u === 1 ? "" : message.user_name;
53
    }
54
  };
1191 stevensc 55
 
1198 stevensc 56
  const handleLike = () => {
57
    setIsLiked(!isLiked)
1199 stevensc 58
    setIsShow(!isShow)
1198 stevensc 59
  }
60
 
2765 stevensc 61
  const handleResponse = (msg) => {
62
    setIsShow(false)
63
    setResponseMessage(msg)
64
  }
65
 
1334 stevensc 66
  const handleCopy = async () => {
67
    await navigator.clipboard.writeText(`${message.m}`)
68
    dispatch(addNotification({
69
      style: "success",
70
      msg: 'Mensaje copiado en el portapapeles',
71
    }))
1381 stevensc 72
    setIsShow(!isShow)
1331 stevensc 73
  }
74
 
1 www 75
  switch (message.mtype) {
76
    case "text":
77
      return (
78
        <li
79
          key={message.id}
1305 stevensc 80
          className={`clearfix ${message.u === 1 ? "odd" : ""} m-t-10 conversers${message.u}`}
1 www 81
        >
1305 stevensc 82
          <div className="conversation-text">
2138 steven 83
            <div className="conversation_container w-100">
1198 stevensc 84
              {
1305 stevensc 85
                responseMessage
1198 stevensc 86
                &&
1306 stevensc 87
                <ResponseMessageContainer isRight={message.u === 1}>
1305 stevensc 88
                  <span>{`Respondiendo a ${responseMessage.user_name}`}</span>
89
                  <div className="ctext-wrap">
90
                    {senderName(responseMessage)}
91
                    <p className="">
92
                      {parse(emojione.shortnameToImage(responseMessage.m))}
93
                      <br />
94
                    </p>
95
                  </div>
96
                </ResponseMessageContainer>
97
              }
98
              <div className="conversation-text">
99
                <div className="ctext-wrap">
100
                  {senderName(message)}
101
                  <p className="">
102
                    {parse(emojione.shortnameToImage(message.m))}
103
                    <br />
2185 stevensc 104
                    <div className="d-inline-flex align-items-center">
2186 stevensc 105
                      {
106
                        !message.not_received
107
                        &&
108
                        <i className={"fa fa-check text-right ellipsis "} style={message.seen ? { color: 'blue' } : { color: 'gray' }} />
109
                      }
2184 stevensc 110
                      <label>{message.time}</label>
111
                    </div>
1305 stevensc 112
                  </p>
113
                  {
114
                    isLiked
115
                    &&
116
                    <i
117
                      className="fas fa-heart"
118
                      style={{
119
                        color: '#0961bf',
120
                        position: 'absolute',
121
                        top: '87%',
122
                        left: '85%'
123
                      }}
124
                    />
125
                  }
126
                </div>
2273 steven 127
                <i
1305 stevensc 128
                  className="la la-ellipsis-v icon"
129
                  style={{ position: 'relative' }}
130
                  onClick={() => setIsShow(!isShow)}
2765 stevensc 131
                />
1305 stevensc 132
                {
133
                  isShow
134
                  &&
2765 stevensc 135
                  <div className="display-reactions" >
136
                    <LikeButton onClick={handleLike} />
137
                    <button type="button" onClick={() => handleResponse(message)}>
138
                      <i className="fa fa-reply" />
1305 stevensc 139
                    </button>
2765 stevensc 140
                    <button type="button" onClick={() => handleCopy(message)}>
141
                      <i className="fa fa-copy" />
1331 stevensc 142
                    </button>
1305 stevensc 143
                  </div>
144
                }
1197 stevensc 145
              </div>
1305 stevensc 146
            </div>
1 www 147
          </div>
148
        </li>
149
      );
150
    case "image":
151
      return (
152
        <li
153
          key={message.id}
2765 stevensc 154
          className={`clearfix ${message.u === 1 ? "odd" : ""} m-t-10 conversers${message.u}`}
1 www 155
        >
156
          <div
157
            className="conversation-text"
158
            data-toggle="tooltip"
159
            data-placement="left"
160
            data-html="true"
161
          >
162
            <div className="ctext-wrap">
163
              {senderName(message)}
164
              <StyledChatImgMessage>
165
                <div className="chat_image_container">
166
                  <img src={message.m} alt="chat_image" />
167
                </div>
2762 stevensc 168
                {
2763 stevensc 169
                  message.u !== 1
2762 stevensc 170
                  &&
1 www 171
                  <a
172
                    href={message.m}
2762 stevensc 173
                    download
1 www 174
                    className="chat_image__download_button"
175
                  >
2762 stevensc 176
                    <i className="fa fa-arrow-circle-o-down" />
1 www 177
                  </a>
2762 stevensc 178
                }
1 www 179
              </StyledChatImgMessage>
180
              <br />
181
              <i className="text-right">{message.time}</i>
2765 stevensc 182
              {
183
                isLiked
184
                &&
185
                <i
186
                  className="fas fa-heart"
187
                  style={{
188
                    color: '#0961bf',
189
                    position: 'absolute',
190
                    top: '87%',
191
                    left: '85%'
192
                  }}
193
                />
194
              }
1 www 195
            </div>
2765 stevensc 196
            <i
197
              className="la la-ellipsis-v icon"
198
              style={{ position: 'relative' }}
199
              onClick={() => setIsShow(!isShow)}
200
            />
2762 stevensc 201
            {
202
              isShow
203
              &&
204
              <div className="display-reactions">
2765 stevensc 205
                <LikeButton onClick={handleLike} />
2762 stevensc 206
              </div>
207
            }
1 www 208
          </div>
209
        </li>
210
      );
211
    case "video":
212
      return (
213
        <li
214
          key={message.id}
2765 stevensc 215
          className={`clearfix ${message.u === 1 ? "odd" : ""} m-t-10 conversers${message.u}`}
1 www 216
        >
217
          <div
218
            className="conversation-text"
219
            data-toggle="tooltip"
220
            data-placement="left"
221
            data-html="true"
222
          >
223
            <div className="ctext-wrap">
224
              {senderName(message)}
225
              <StyledChatImgMessage>
2764 stevensc 226
                <a
227
                  href={message.m}
228
                  target="_blank"
229
                  className="chat_image__download_button"
230
                >
231
                  <div className="chat_image_container">
232
                    <video src={message.m} preload="none" controls></video>
233
                  </div>
234
                </a>
235
                {message.u !== 1
236
                  &&
1 www 237
                  <a
238
                    href={message.m}
2764 stevensc 239
                    download
1 www 240
                    className="chat_image__download_button"
241
                  >
2764 stevensc 242
                    <i className="fa fa-arrow-circle-o-down" />
1 www 243
                  </a>
2764 stevensc 244
                }
1 www 245
              </StyledChatImgMessage>
246
              <br />
247
              <i className="text-right">{message.time}</i>
2765 stevensc 248
              {
249
                isLiked
250
                &&
251
                <i
252
                  className="fas fa-heart"
253
                  style={{
254
                    color: '#0961bf',
255
                    position: 'absolute',
256
                    top: '87%',
257
                    left: '85%'
258
                  }}
259
                />
260
              }
1 www 261
            </div>
2765 stevensc 262
            <i
263
              className="la la-ellipsis-v icon"
264
              style={{ position: 'relative' }}
265
              onClick={() => setIsShow(!isShow)}
266
            />
267
            {
268
              isShow
269
              &&
270
              <div className="display-reactions">
271
                <LikeButton onClick={handleLike} />
272
              </div>
273
            }
1 www 274
          </div>
275
        </li>
276
      );
277
    case "document":
278
      return (
279
        <li
280
          key={message.id}
2765 stevensc 281
          className={`clearfix ${message.u === 1 ? "odd" : ""} m-t-10 conversers${message.u}`}
1 www 282
        >
283
          <div
284
            className="conversation-text"
285
            data-toggle="tooltip"
286
            data-placement="left"
287
            data-html="true"
288
          >
289
            <div className="ctext-wrap">
290
              {senderName(message)}
291
              <StyledChatImgMessage>
292
                <div className="chat_image_container">
293
                  <img
294
                    className="pdf"
295
                    src="/storage/type/default/filename/pdf.png"
296
                    alt="pdf"
297
                  />
298
                </div>
2764 stevensc 299
                {message.u !== 1
300
                  &&
1 www 301
                  <a
302
                    href={message.m}
303
                    target="_blank"
304
                    className="chat_image__download_button"
305
                  >
306
                    <i className="fa ti-arrow-circle-down"></i>
307
                  </a>
2764 stevensc 308
                }
1 www 309
              </StyledChatImgMessage>
310
              <br />
311
              <i className="text-right">{message.time}</i>
2765 stevensc 312
              {
313
                isLiked
314
                &&
315
                <i
316
                  className="fas fa-heart"
317
                  style={{
318
                    color: '#0961bf',
319
                    position: 'absolute',
320
                    top: '87%',
321
                    left: '85%'
322
                  }}
323
                />
324
              }
1 www 325
            </div>
2765 stevensc 326
            <i
327
              className="la la-ellipsis-v icon"
328
              style={{ position: 'relative' }}
329
              onClick={() => setIsShow(!isShow)}
330
            />
331
            {
332
              isShow
333
              &&
334
              <div className="display-reactions">
335
                <LikeButton onClick={handleLike} />
336
              </div>
337
            }
1 www 338
          </div>
339
        </li>
340
      );
341
    default:
342
      return (
343
        <li
344
          key={message.id}
2765 stevensc 345
          className={`clearfix ${message.u === 1 ? "odd" : ""} m-t-10 conversers${message.u}`}
1 www 346
        >
347
          <div
348
            className="conversation-text"
349
            data-toggle="tooltip"
350
            data-placement="left"
351
            data-html="true"
352
          >
353
            <div className="ctext-wrap">
354
              {senderName(message)}
2765 stevensc 355
              <p>
1 www 356
                {message.mtype}
357
                <br />
358
                <i className="text-right">{message.time}</i>
359
              </p>
360
            </div>
2765 stevensc 361
            <i
362
              className="la la-ellipsis-v icon"
363
              style={{ position: 'relative' }}
364
              onClick={() => setIsShow(!isShow)}
365
            />
366
            {
367
              isShow
368
              &&
369
              <div className="display-reactions">
370
                <LikeButton onClick={handleLike} />
371
                <button type="button" onClick={() => setResponseMessage(message)}>
372
                  <i className="fa fa-reply" />
373
                </button>
374
              </div>
375
            }
1 www 376
          </div>
377
        </li>
378
      );
379
  }
380
};
381
 
382
export default MessageTemplate;