|
@@ -1,10 +1,12 @@
|
|
import React, {useState, useEffect, useRef} from 'react'
|
|
import React, {useState, useEffect, useRef} from 'react'
|
|
|
|
+import ReactDOM from "react-dom";
|
|
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
|
import FileDownloadIcon from '@mui/icons-material/FileDownload';
|
|
import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile';
|
|
import InsertDriveFileIcon from '@mui/icons-material/InsertDriveFile';
|
|
-import Popper from '@mui/material/Popper';
|
|
|
|
-
|
|
|
|
|
|
+import Popover from '@mui/material/Popover';
|
|
|
|
+import List from '@mui/material/List';
|
|
|
|
+import ListItemButton from '@mui/material/ListItemButton';
|
|
import { connect } from 'react-redux'
|
|
import { connect } from 'react-redux'
|
|
-import { dateFromStamp, stringColor, backURL } from '../helpers'
|
|
|
|
|
|
+import { dateFromStamp, stringColor, backURL, decorateLinks } from '../helpers'
|
|
|
|
|
|
import { UserAvatar, CMyAvatar } from '.'
|
|
import { UserAvatar, CMyAvatar } from '.'
|
|
|
|
|
|
@@ -15,8 +17,9 @@ const msgBlock = {
|
|
justifyContent: "flex-start",
|
|
justifyContent: "flex-start",
|
|
alignItems: "start",
|
|
alignItems: "start",
|
|
margin: "2px",
|
|
margin: "2px",
|
|
|
|
+ marginLeft: "10px",
|
|
marginRight: "5%",
|
|
marginRight: "5%",
|
|
- maxWidth: "calc(95% - 2px)",
|
|
|
|
|
|
+ maxWidth: "calc(95% - 10px)",
|
|
minWidth: "40%",
|
|
minWidth: "40%",
|
|
wordWrap: "break-word",
|
|
wordWrap: "break-word",
|
|
}
|
|
}
|
|
@@ -27,8 +30,9 @@ const myMsgBlock = {
|
|
justifyContent: "flex-start",
|
|
justifyContent: "flex-start",
|
|
alignItems: "start",
|
|
alignItems: "start",
|
|
margin: "2px",
|
|
margin: "2px",
|
|
|
|
+ marginRight: "10px",
|
|
marginLeft: "5%",
|
|
marginLeft: "5%",
|
|
- maxWidth: "calc(95% - 2px)",
|
|
|
|
|
|
+ maxWidth: "calc(95% - 10px)",
|
|
minWidth: "40%",
|
|
minWidth: "40%",
|
|
wordWrap: "break-word",
|
|
wordWrap: "break-word",
|
|
}
|
|
}
|
|
@@ -123,14 +127,14 @@ const textDownload = {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-const Msg = ({ msg, prevOwner, prevTime, myProfile, onEvent }) => {
|
|
|
|
|
|
+const Msg = ({ msg, myProfile, onEdit }) => {
|
|
|
|
|
|
const myId = myProfile?._id || null
|
|
const myId = myProfile?._id || null
|
|
const myLogin = myProfile?.login || null
|
|
const myLogin = myProfile?.login || null
|
|
const myNick = myProfile?.nick || null
|
|
const myNick = myProfile?.nick || null
|
|
|
|
|
|
- const { _id, text, owner, media, createdAt } = msg
|
|
|
|
- const {nick, login, avatar} = owner
|
|
|
|
|
|
+ const { _id, text, owner, media, createdAt, nextOwner, nextTime } = msg
|
|
|
|
+ const { nick, login, avatar } = owner
|
|
|
|
|
|
const allMedia = {}
|
|
const allMedia = {}
|
|
if (media) for (const file of media) {
|
|
if (media) for (const file of media) {
|
|
@@ -145,28 +149,87 @@ const Msg = ({ msg, prevOwner, prevTime, myProfile, onEvent }) => {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ // console.log(allMedia)
|
|
|
|
|
|
- const prOwner = prevOwner.current
|
|
|
|
- prevOwner.current = owner._id
|
|
|
|
|
|
|
|
- const prTime = prevTime.current
|
|
|
|
- prevTime.current = createdAt
|
|
|
|
|
|
+ const [anchorEl, setAnchorEl] = useState(null)
|
|
|
|
+ // const [top, setTop] = useState(0)
|
|
|
|
+ // const [left, setLeft] = useState(0)
|
|
|
|
+
|
|
|
|
+ const handleClick = (e) => {
|
|
|
|
+ // e.preventDefault()
|
|
|
|
+ // console.log(e)
|
|
|
|
+ // if (e.button === 2) {
|
|
|
|
+ // console.log('dasdadasdas')
|
|
|
|
+ // }
|
|
|
|
+ // console.log(e.pageX - e.target.offsetLeft, e.pageY - e.target.offsetTop)
|
|
|
|
+ // console.log(e.target.offsetTop, e.target.offsetLeft)
|
|
|
|
+
|
|
|
|
+ // setTop(e.clientY)
|
|
|
|
+ // setLeft(e.clientX)
|
|
|
|
+ setAnchorEl(e.currentTarget)
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const handleClose = () => {
|
|
|
|
+ setAnchorEl(null)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const open = Boolean(anchorEl);
|
|
|
|
+
|
|
|
|
|
|
- // console.log( prTime - createdAt, text)
|
|
|
|
const nameBlockNew = {...nameBlock, color: stringColor.stringToColor(nick || login)}
|
|
const nameBlockNew = {...nameBlock, color: stringColor.stringToColor(nick || login)}
|
|
return (
|
|
return (
|
|
- <div onClick={onEvent}
|
|
|
|
- style={(myId === owner._id) ?
|
|
|
|
- ( (prOwner === owner._id) ?
|
|
|
|
- {...myMsgBlock, marginBottom: "2px"} : {...myMsgBlock, marginBottom: "15px"}) :
|
|
|
|
- ( (prOwner === owner._id) ?
|
|
|
|
- {...msgBlock, marginBottom: "2px"} : {...msgBlock, marginBottom: "15px"})
|
|
|
|
|
|
+ <>
|
|
|
|
+ <Popover
|
|
|
|
+ open={open}
|
|
|
|
+ anchorEl={anchorEl}
|
|
|
|
+ onClose={handleClose}
|
|
|
|
+ anchorOrigin={{
|
|
|
|
+ vertical: 'bottom',
|
|
|
|
+ horizontal: 'left',
|
|
|
|
+ }}
|
|
|
|
+ // anchorPosition={{
|
|
|
|
+ // top: 300,
|
|
|
|
+ // left: 300
|
|
|
|
+ // }}
|
|
|
|
+ >
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ <List sx={{ width: '100%', maxWidth: 300, bgcolor: 'background.paper' }}>
|
|
|
|
+
|
|
|
|
+ <ListItemButton onClick={() => {
|
|
|
|
+ handleClose()
|
|
|
|
+ }}>
|
|
|
|
+ Ответить
|
|
|
|
+ </ListItemButton>
|
|
|
|
+
|
|
|
|
+ <ListItemButton onClick={() => {
|
|
|
|
+ onEdit(msg);
|
|
|
|
+ handleClose()
|
|
|
|
+ }} >
|
|
|
|
+ Редактировать
|
|
|
|
+ </ListItemButton>
|
|
|
|
+
|
|
|
|
+ </List>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ </Popover>
|
|
|
|
+
|
|
|
|
+ <div onContextMenu={handleClick}
|
|
|
|
+
|
|
|
|
+ style={ (myId === owner._id) ?
|
|
|
|
+ ( (nextOwner === owner._id) ?
|
|
|
|
+ {...myMsgBlock, marginBottom: "2px"} : {...myMsgBlock, marginBottom: "15px"}) :
|
|
|
|
+ ( (nextOwner === owner._id) ?
|
|
|
|
+ {...msgBlock, marginBottom: "2px"} : {...msgBlock, marginBottom: "15px"})
|
|
}
|
|
}
|
|
- >
|
|
|
|
|
|
+ >
|
|
|
|
|
|
<div style={avBlock} >
|
|
<div style={avBlock} >
|
|
- { (prOwner === owner._id &&
|
|
|
|
- prTime - createdAt < 600000) ||
|
|
|
|
|
|
+ { (nextOwner === owner._id &&
|
|
|
|
+ nextTime - createdAt < 600000) ||
|
|
( (myId === owner._id) ?
|
|
( (myId === owner._id) ?
|
|
<CMyAvatar /> :
|
|
<CMyAvatar /> :
|
|
<UserAvatar profile={owner} /> ) }
|
|
<UserAvatar profile={owner} /> ) }
|
|
@@ -186,10 +249,11 @@ const Msg = ({ msg, prevOwner, prevTime, myProfile, onEvent }) => {
|
|
{
|
|
{
|
|
(key === 'image') &&
|
|
(key === 'image') &&
|
|
allMedia[key].map((mediaObj) =>
|
|
allMedia[key].map((mediaObj) =>
|
|
- <img
|
|
|
|
|
|
+ <img
|
|
key={mediaObj.url}
|
|
key={mediaObj.url}
|
|
style={imgStyle}
|
|
style={imgStyle}
|
|
src={backURL + mediaObj.url}
|
|
src={backURL + mediaObj.url}
|
|
|
|
+ type={mediaObj.type}
|
|
/>
|
|
/>
|
|
) ||
|
|
) ||
|
|
(key === 'video') &&
|
|
(key === 'video') &&
|
|
@@ -253,6 +317,7 @@ const Msg = ({ msg, prevOwner, prevTime, myProfile, onEvent }) => {
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
+ </>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
export const CMsg = connect( state => ({ myProfile: state.promise.myProfile?.payload || {}}))(Msg)
|
|
export const CMsg = connect( state => ({ myProfile: state.promise.myProfile?.payload || {}}))(Msg)
|
|
@@ -260,36 +325,6 @@ export const CMsg = connect( state => ({ myProfile: state.promise.myProfile?.pay
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-export const MsgMenu = (props) => {
|
|
|
|
-
|
|
|
|
- const [anchorEl, setAnchorEl] = useState(null);
|
|
|
|
-
|
|
|
|
- const handleClick = (e) => {
|
|
|
|
- e.preventDefault()
|
|
|
|
- if (e.button === 2) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- setAnchorEl(anchorEl ? null : e.currentTarget);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- const open = Boolean(anchorEl);
|
|
|
|
-
|
|
|
|
- return (
|
|
|
|
- <div>
|
|
|
|
-
|
|
|
|
- <CMsg {...props} onEvent={handleClick} />
|
|
|
|
-
|
|
|
|
- <Popper open={open} anchorEl={anchorEl}>
|
|
|
|
-
|
|
|
|
- <div style={{ backgroundColor: "#fff"}} >
|
|
|
|
- РЕДАКТИРОВАНИЕ
|
|
|
|
- </div>
|
|
|
|
- </Popper>
|
|
|
|
- </div>
|
|
|
|
- )
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|