InputAreaMessageEditor.jsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 {MessageEditor} from "../MessageDraft/MessageEditor";
  10. const InputAreaMessageEditor = ({chats, chatId, deleteMessageEditor, sendMessage, setInputValue}) => {
  11. const inputValue = chats[chatId]?.draft?.messageEditor?.value || '';
  12. const messageId = chats[chatId]?.draft?.messageEditor?.message._id;
  13. const message = chats[chatId]?.draft?.messageEditor?.message;
  14. return (
  15. <InputAreaWrapper>
  16. <MessageEditor deleteMessageEditor={deleteMessageEditor} chatId={chatId} message={message}/>
  17. <div style={{display: 'flex', alignItems: 'center', padding: '10px 0'}}>
  18. <MessageDropZone chatId={chatId}/>
  19. <TextArea
  20. value={inputValue}
  21. onChange={e=>{setInputValue(chatId, e.target.value, 'messageEditor')}}
  22. maxRows={8}
  23. placeholder="Write a message..."
  24. />
  25. {inputValue ?
  26. <SendRoundedIcon
  27. style={{margin: '0 16px', cursor: "pointer"}}
  28. color="primary"
  29. // src={Plane}
  30. onClick={
  31. async() => {
  32. let val = await sendMessage(messageId, null, inputValue.replace(/^\s+|\s+$/g, ''), null, null);
  33. val && deleteMessageEditor(chatId, null);
  34. }
  35. }
  36. /> : <div></div>}
  37. </div>
  38. </InputAreaWrapper>
  39. )
  40. }
  41. export default connect(state => ({chats: state.chats}), {
  42. sendMessage: actionSendMessage,
  43. setInputValue: actionSetInputMessageValue,
  44. deleteMessageEditor: actionSetMessageEditor
  45. })(InputAreaMessageEditor);