InputAreaMessageEditor.jsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { useEffect, useRef, useState } from "react"
  2. import { connect } from "react-redux"
  3. import { actionSendMessage, actionUpsertMSG } from "../../actions/actionsMessages"
  4. import { InputAreaWrapper, TextArea} from "./InputArea.style";
  5. import Plane from "./icons8-plane.png";
  6. import MessageDropZone from "../DropZone/MessageDropZone/MessageDropZone";
  7. import { actionDeleteDraftMessageId, actionDeleteReplyMessageId, actionSetInputMessageValue, actionSetMessageEditor } from "../../reducers/chatReducer";
  8. import SendRoundedIcon from '@mui/icons-material/SendRounded';
  9. import { MessageDraftBox } from "../MessageDraft/MessageDraftBox";
  10. import {MessageEditor} from "../MessageDraft/MessageEditor";
  11. const InputAreaMessageEditor = ({chats, chatId, deleteMessageEditor, sendMessage, setInputValue}) => {
  12. const inputValue = chats[chatId]?.draft?.messageEditor?.value || '';
  13. const messageId = chats[chatId]?.draft?.messageEditor?.message._id;
  14. const message = chats[chatId]?.draft?.messageEditor?.message;
  15. return (
  16. <InputAreaWrapper>
  17. <MessageEditor deleteMessageEditor={deleteMessageEditor} chatId={chatId} message={message}/>
  18. <div style={{display: 'flex', alignItems: 'center', padding: '10px 0'}}>
  19. <MessageDropZone chatId={chatId}/>
  20. <TextArea
  21. value={inputValue}
  22. onChange={e=>{setInputValue(chatId, e.target.value, 'messageEditor')}}
  23. maxRows={8}
  24. placeholder="Write a message..."
  25. />
  26. {inputValue ?
  27. <SendRoundedIcon
  28. style={{margin: '0 16px', cursor: "pointer"}}
  29. color="primary"
  30. // src={Plane}
  31. onClick={
  32. async() => {
  33. let val = await sendMessage(messageId, null, inputValue.replace(/^\s+|\s+$/g, ''), null, null);
  34. val && deleteMessageEditor(chatId, null);
  35. }
  36. }
  37. /> : <div></div>}
  38. </div>
  39. </InputAreaWrapper>
  40. )
  41. }
  42. export default connect(state => ({chats: state.chats}), {
  43. sendMessage: actionSendMessage,
  44. setInputValue: actionSetInputMessageValue,
  45. deleteMessageEditor: actionSetMessageEditor
  46. })(InputAreaMessageEditor);