Proyectos de Subversion LeadersLinked - Backend

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
15762 stevensc 1
/* eslint-disable react/prop-types */
2
import React, { Suspense, useRef, useState } from "react";
3
import AttachFileIcon from "@mui/icons-material/AttachFile";
4
import SentimentVerySatisfiedRoundedIcon from "@mui/icons-material/SentimentVerySatisfiedRounded";
5
import Emojione from "../personal-chat/emojione/Emojione";
6
const SendFileModal = React.lazy(() =>
7
  import("../personal-chat/send-file-modal/SendFileModal")
8
);
9
 
10
const TextBox = ({
11
  uploadUrl = "",
12
  isNotSeen = false,
13
  markRead = () => false,
14
  onSend,
15
}) => {
16
  const [showEmojiTab, setShowEmojiTab] = useState(false);
17
  const [showFileModal, setShowFileModal] = useState(false);
18
  const textAreaEl = useRef(null);
19
 
20
  const handleshowFileModal = () => setShowFileModal(!showFileModal);
21
 
22
  const handleShowEmojiTab = () => setShowEmojiTab(!showEmojiTab);
23
 
24
  const handleClickEmoji = (e) => {
25
    const shortname = e.currentTarget.dataset.shortname;
26
    const currentText = textAreaEl.current.value;
27
    const cursorPosition = textAreaEl.current.selectionStart;
28
    const textBehind = currentText.substring(0, cursorPosition);
29
    const textForward = currentText.substring(cursorPosition);
30
    const unicode = emojione.shortnameToUnicode(shortname);
31
    textAreaEl.current.value = `${textBehind}${unicode}${textForward}`;
32
    textAreaEl.current.focus();
33
    textAreaEl.current.setSelectionRange(
34
      cursorPosition + unicode.length,
35
      cursorPosition + unicode.length
36
    );
37
  };
38
 
39
  const onKeyDown = async (e) => {
40
    if (e.key !== "Enter") return false;
41
    e.preventDefault();
42
    const message = e.target.value;
43
    await onSend(message);
44
    e.target.value = "";
45
    setShowEmojiTab(false);
46
  };
47
 
48
  return (
49
    <>
50
      <div className="chat-text_box">
51
        <AttachFileIcon onClick={handleshowFileModal} />
52
        <SentimentVerySatisfiedRoundedIcon onClick={handleShowEmojiTab} />
53
        <textarea
54
          placeholder={CHAT_LABELS.WRITE_A_MESSAGE}
55
          onKeyDown={onKeyDown}
56
          ref={textAreaEl}
57
          onFocus={() => isNotSeen && markRead()}
58
        />
59
        <div
60
          className="emojione-container"
61
          style={{ display: showEmojiTab ? "block" : "none" }}
62
        >
63
          <Emojione onClickEmoji={handleClickEmoji} />
64
        </div>
65
      </div>
66
      {showFileModal && (
67
        <Suspense fallback={null}>
68
          <SendFileModal
69
            show={true}
70
            onHide={() => setShowFileModal(false)}
71
            urlUpload={uploadUrl}
72
          />
73
        </Suspense>
74
      )}
75
    </>
76
  );
77
};
78
 
79
export default TextBox;