|
@@ -1,8 +1,176 @@
|
|
|
|
+import React, {useState, useEffect, useRef} from 'react';
|
|
|
|
+import Box from '@mui/material/Box';
|
|
|
|
+import Button from '@mui/material/Button';
|
|
|
|
+import TextareaAutosize from '@mui/base/TextareaAutosize';
|
|
|
|
+import SendIcon from '@mui/icons-material/Send';
|
|
|
|
+import AttachFileIcon from '@mui/icons-material/AttachFile';
|
|
|
|
+import CloseIcon from '@mui/icons-material/Close';
|
|
|
|
|
|
|
|
+import {useDropzone} from 'react-dropzone';
|
|
|
|
|
|
|
|
+import {connect} from 'react-redux'
|
|
|
|
+import {
|
|
|
|
+ actionUploadFile,
|
|
|
|
+} from "../actions"
|
|
|
|
+
|
|
|
|
+const containerWrapp = {
|
|
|
|
+ // width: '80%',
|
|
|
|
+ display: 'flex',
|
|
|
|
+ flexDirection: 'column',
|
|
|
|
+ padding: '5px',
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+const thumbsContainer = {
|
|
|
|
+ flexGrow: '0',
|
|
|
|
+ display: 'flex',
|
|
|
|
+ flexDirection: 'row',
|
|
|
|
+ flexWrap: 'wrap',
|
|
|
|
+ width: '100%',
|
|
|
|
+ overflow: 'auto',
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const thumb = {
|
|
|
|
+ flexGrow: '0',
|
|
|
|
+ display: 'inline-flex',
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ borderRadius: 2,
|
|
|
|
+ border: '1px solid #eaeaea',
|
|
|
|
+ marginBottom: 8,
|
|
|
|
+ marginRight: 8,
|
|
|
|
+ width: 100,
|
|
|
|
+ height: 117,
|
|
|
|
+ padding: 4,
|
|
|
|
+ boxSizing: 'border-box',
|
|
|
|
+ position: 'relative',
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const thumbInner = {
|
|
|
|
+ display: 'flex',
|
|
|
|
+ flexDirection: 'column',
|
|
|
|
+ paddingTop: 17,
|
|
|
|
+ minWidth: 0,
|
|
|
|
+ overflow: 'hidden'
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const closeBtn = {
|
|
|
|
+ position: 'absolute',
|
|
|
|
+ right: 0,
|
|
|
|
+ display: 'flex',
|
|
|
|
+ justifyContent: 'end',
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const img = {
|
|
|
|
+ display: 'block',
|
|
|
|
+ width: 'auto',
|
|
|
|
+ height: '100%'
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+const MsgDropZone = ({onText, setFiles}) => {
|
|
|
|
+
|
|
|
|
+ const [localFiles, setLocalFiles] = useState([]);
|
|
|
|
+
|
|
|
|
+ const {
|
|
|
|
+ acceptedFiles,
|
|
|
|
+ getRootProps,
|
|
|
|
+ getInputProps
|
|
|
|
+ } = useDropzone({
|
|
|
|
+ noKeyboard: true,
|
|
|
|
+ onDrop: async (acceptedFiles) => {
|
|
|
|
+
|
|
|
|
+ console.log(acceptedFiles)
|
|
|
|
+
|
|
|
|
+ await setLocalFiles([...localFiles,
|
|
|
|
+ ...acceptedFiles.map(file => Object.assign(file, {
|
|
|
|
+ preview: URL.createObjectURL(file)
|
|
|
|
+ }))
|
|
|
|
+ ]);
|
|
|
|
+
|
|
|
|
+ await acceptedFiles.map(file => {
|
|
|
|
+ setFiles(file)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ console.log(localFiles)
|
|
|
|
+
|
|
|
|
+ const thumbs = localFiles.map((file, index) => (
|
|
|
|
+ <div style={thumb} key={file.preview}>
|
|
|
|
+ <div style={closeBtn}>
|
|
|
|
+ <CloseIcon
|
|
|
|
+ fontSize="small"
|
|
|
|
+ sx={{ cursor: 'pointer' }}
|
|
|
|
+ onClick={() => {}}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ <div style={thumbInner}>
|
|
|
|
+ <img
|
|
|
|
+ src={file.preview}
|
|
|
|
+ style={img}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ </div>
|
|
|
|
+ ));
|
|
|
|
+
|
|
|
|
+ // useEffect(() => {
|
|
|
|
+ // // Make sure to revoke the data uris to avoid memory leaks
|
|
|
|
+ // localFiles.forEach(file => URL.revokeObjectURL(file.preview));
|
|
|
|
+ // }, [localFiles]);
|
|
|
|
+
|
|
|
|
+ return (
|
|
|
|
+ <>
|
|
|
|
+ <form action="/upload" method="post" encType="multipart/form-data" id='form'>
|
|
|
|
+ <section style={containerWrapp}>
|
|
|
|
+
|
|
|
|
+ <div style={thumbsContainer}>
|
|
|
|
+ {thumbs}
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ <div {...getRootProps({className: 'dropzone'})} style={{ display: 'flex', alignItems: 'center'}}>
|
|
|
|
+ <input {...getInputProps()} type="file" name="media" id='media'/>
|
|
|
|
+
|
|
|
|
+ <AttachFileIcon fontSize="large" sx={{ cursor: 'pointer' }} />
|
|
|
|
+
|
|
|
|
+ <TextareaAutosize
|
|
|
|
+ minRows={4}
|
|
|
|
+ maxRows={10}
|
|
|
|
+ placeholder="Сообщение"
|
|
|
|
+ style={{ width: '100%' }}
|
|
|
|
+ onClick={(e) => e.stopPropagation()}
|
|
|
|
+ onChange={() => onText()}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+
|
|
|
|
+ </section>
|
|
|
|
+ </form>
|
|
|
|
+ </>
|
|
|
|
+ )
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+const SendingField = ({onSend}) => {
|
|
|
|
+ const [text, setText] = useState('')
|
|
|
|
+ const [files, setFiles] = useState([])
|
|
|
|
|
|
-export const SendingField = () => {
|
|
|
|
return (
|
|
return (
|
|
- <></>
|
|
|
|
|
|
+ <Box sx={{ display: 'flex', alignItems: 'center', height: '100%', width: '100%'}} >
|
|
|
|
+
|
|
|
|
+ <Box sx={{ flexGrow: 1, flexShrink: 1, flexBasis: '80%', overflow: 'auto', height: '100%', backgroundColor: '#fff' }}>
|
|
|
|
+ <MsgDropZone onText={setText} onFile={setFiles} />
|
|
|
|
+ </Box>
|
|
|
|
+ <Box sx={{ flexGrow: 1, flexShrink: 0, flexBasis: '50px'}}>
|
|
|
|
+ <Button
|
|
|
|
+ variant="contained"
|
|
|
|
+ endIcon={<SendIcon />}
|
|
|
|
+ onClick={() => onSend(text, files)}
|
|
|
|
+ >
|
|
|
|
+ Отправить
|
|
|
|
+ </Button>
|
|
|
|
+ </Box>
|
|
|
|
+
|
|
|
|
+ </Box>
|
|
)
|
|
)
|
|
-}
|
|
|
|
|
|
+}
|
|
|
|
+export const CSendingField= connect( null, {onSend: actionUploadFile})(SendingField)
|