InputAreaMessageEditor.jsx 2.1 KB

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