123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- import { makeStyles } from "@material-ui/core/styles";
- import { styled } from '@mui/material/styles';
- import { useState } from "react";
- import Typography from '@mui/material/Typography';
- import ListItemText from '@mui/material/ListItemText';
- import Button from '@mui/material/Button';
- import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
- import Menu from '@mui/material/Menu';
- import MenuItem from '@mui/material/MenuItem';
- import Divider from '@mui/material/Divider';
- import CheckBoxIcon from '@mui/icons-material/CheckBox';
- import Checkbox from '@mui/material/Checkbox';
- import PushPinIcon from '@mui/icons-material/PushPin';
- import CloseIcon from '@mui/icons-material/Close';
- import ReplyIcon from '@mui/icons-material/Reply';
- import LibraryMusicIcon from '@mui/icons-material/LibraryMusic';
- import FolderIcon from '@mui/icons-material/Folder';
- import ImageIcon from '@mui/icons-material/Image';
- import ContentCopyIcon from '@mui/icons-material/ContentCopy';
- import VideoLibraryIcon from '@mui/icons-material/VideoLibrary';
- import { CopyToClipboard } from 'react-copy-to-clipboard';
- import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
- import { firstLetter,slicedWord,timeStampMessage,copied,emojisArr,handleDownload } from '../../../../../../helpers'
- const StyledMenu = styled((props:any) => (
- <Menu
- elevation={0}
- anchorOrigin={{
- vertical: 'top',
- horizontal: 'right',
- }}
- transformOrigin={{
- vertical: 'bottom',
- horizontal: 'right',
- }}
- {...props}
- />
- ))(({ theme }:any) => ({
- '& .MuiPaper-root': {
- borderRadius: 10,
- marginTop: theme.spacing(0),
- minWidth: 220,
- color:
- theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
- boxShadow:
- 'rgb(255, 255, 255) 0px 0px 0px 0px, rgba(0, 0, 0, 0.05) 0px 0px 0px 1px, rgba(0, 0, 0, 0.1) 0px 10px 15px -3px, rgba(0, 0, 0, 0.05) 0px 4px 6px -2px',
- '& .MuiMenu-list': {
- padding: '4px 4px',
- },
- '& .MuiMenuItem-root': {
- marginBottom: theme.spacing(1),
- '& .MuiSvgIcon-root': {
- fontSize: 21,
- color: theme.palette.text.secondary,
- marginRight: theme.spacing(2),
- }
- },
- },
- }));
- const useStyles = makeStyles({
- container: {
- display: "flex",
- alignItems: 'flex-start',
- alignContent: 'flex-start',
- flexDirection:'column',
- borderRadius: 7,
- position: 'relative',
- marginBottom: 5,
- padding:'10px 0px 10px 22px'
- },
- wrapper: {
- position: 'relative',
- display: 'flex',
- alignItems: 'center',
- alignContent: 'center',
- flexWrap: 'wrap',
- maxWidth: 450,
- minWidth:200,
- padding: "10px",
- paddingBottom:18,
- backgroundColor: "#ffffff",
- border: "1px solid #f0f0f0",
- borderRadius: 7,
- },
- wrapperInner: {
- position:'relative',
- display: 'flex',
- alignItems: 'center',
- alignContent: 'center',
- width:'100%'
- },
- wrapperInnerMessage: {
- display: 'flex',
- alignItems: 'center',
- alignContent: 'center',
- flexWrap: 'wrap',
- marginLeft:20,
- wordBreak:'break-word',
- textAlign: "left",
- font: "400 .9em 'Open Sans', sans-serif",
- },
- message: {
- wordBreak:'break-word',
- textAlign: "left",
- font: "400 .9em 'Open Sans', sans-serif",
- "&:after": {
- content: "''",
- position: "absolute",
- width: "0",
- height: "0",
- borderBottom: "15px solid #ffffff",
- borderLeft: "15px solid transparent",
- borderRight: "15px solid transparent",
- bottom: '0px',
- left: "-15px"
- },
- "&:before": {
- content: "''",
- position: "absolute",
- width: "0",
- height: "0",
- borderBottom: "17px solid #ffffff",
- borderLeft: "16px solid transparent",
- borderRight: "16px solid transparent",
- bottom: "-1px",
- left: "-17px"
- }
- },
- messageActive: {
- wordBreak:'break-word',
- textAlign: "left",
- font: "400 .9em 'Open Sans', sans-serif",
- "&:after": {
- content: "''",
- position: "absolute",
- width: "0",
- height: "0",
- borderBottom: "15px solid #babdbc",
- borderLeft: "15px solid transparent",
- borderRight: "15px solid transparent",
- bottom: '0px',
- left: "-15px"
- },
- "&:before": {
- content: "''",
- position: "absolute",
- width: "0",
- height: "0",
- borderBottom: "17px solid #babdbc",
- borderLeft: "16px solid transparent",
- borderRight: "16px solid transparent",
- bottom: "-1px",
- left: "-17px"
- }
- },
- copyIcon: {
- color: '#b56ff7',
- cursor: 'pointer',
- marginRight: 7,
- '&:hover': {
- color: '#9c3bf8',
- },
- },
- time: {
- position: "absolute",
- fontSize: ".65em",
- fontWeight:600,
- bottom: 6,
- right: 6,
- color: '#414141',
- padding: 3,
- borderRadius: 5,
- },
- captionWrapper: {
- position: 'relative',
- fontSize: ".85em",
- color: '#414141',
- maxWidth: 474,
- fontWeight:600,
- borderRadius: 5,
- marginLeft:10,
- wordBreak:'break-word',
- textAlign: "left",
- font: "400 .9em 'Open Sans', sans-serif",
- backgroundColor: '#deffa9',
- padding:10,
- "&:after": {
- content: "''",
- position: "absolute",
- width: "0",
- height: "0",
- borderBottom: "15px solid #deffa9",
- borderLeft: "15px solid transparent",
- borderRight: "15px solid transparent",
- bottom: "0px",
- left: "-15px"
- },
- "&:before": {
- content: "''",
- position: "absolute",
- width: "0",
- height: "0",
- borderBottom: "17px solid #deffa9",
- borderLeft: "16px solid transparent",
- borderRight: "16px solid transparent",
- bottom: "0px",
- left: "-17px"
- }
- },
- modalDelete: {
- background: '#ffffff',
- position: 'absolute',
- content:'',
- width: '20%',
- height:'auto',
- left: '40%',
- bottom: '48.5%',
- borderRadius: 10,
- padding: 10,
- display: 'flex',
- flexDirection:'column'
- },
- overlay: {
- position: 'fixed',
- top: 0,
- left: 0,
- width: '100vw',
- height: '100vh',
- zIndex: 100,
- backgroundColor: 'rgba(104, 105, 104, 0.6)',
- overflowY: 'hidden',
- },
- emojiTitle: {
- position: "absolute",
- fontSize: "1.7em",
- fontWeight:600,
- bottom: '0.2rem',
- right: -40,
- },
- emojiCompanionTitle: {
- position: "absolute",
- fontSize: "1.7em",
- fontWeight:600,
- bottom: '2.2rem',
- right: -40,
- },
- emoji: {
- cursor: 'pointer',
- fontSize: '1.7rem',
- transition: 'all 0.3s',
- '&:hover': {
- transform: 'scale(1.5)'
- }
- },
- emojiActive: {
- cursor: 'pointer',
- fontSize: '1.2rem',
- animation: `$emoji 0.6s ease-out`,
- animationDirection: 'forwards',
- animationIterationCount: 1,
- },
- '@keyframes emoji': {
- '5%': { transform: 'translateY(1rem)'},
- '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
- '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
- '80%': {opacity: 0},
- '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
- },
- iconClose: {
- '&:hover': {
- transform: 'rotate(180deg)',
- transition: 'all 250ms ease-out ',
- }
- },
- folderIcon: {
- color: '#00b333',
- cursor: 'pointer',
- '&:hover': {
- color: '#00e040'
- },
- },
- replyListItem: {
- display: 'flex',
- width: '100%',
- flexWrap: 'nowrap',
- alignContent: 'center',
- alignItems: 'center',
- },
- checkboxSelect: {
- position: 'absolute',
- left: -64,
- bottom: -10,
- pointerEvents: 'auto'
- },
- replyColumn: {
- position: 'absolute',
- content: '',
- width: 2,
- left:43,
- top:'10%',
- height:'80%',
- backgroundColor: '#00b333',
- },
- });
- const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
- interface IMessageLeftReply {
- url:string,
- replyMessage: string,
- message: string,
- name: string,
- lastName: string,
- replyName:string,
- replyLastName: string,
- replyCaption: string,
- createdAt: string,
- caption: string,
- emoji: string,
- emojiCompanion: string,
- pinned: boolean,
- isSomeSelected: boolean,
- isSelected:(_id:string) => boolean,
- handleSelected: (_id:string) => void,
- _id: string,
- nightMode: boolean,
- handleReply: (_id: string) => void,
- handleForward: (_id: string) => void,
- fullType: string,
- handleScrollToTheMessage: (_id: string) => void,
- oldId: string
- }
- const MessageLeftReply = ({url,replyMessage,message,name,lastName,replyName,replyLastName,replyCaption,createdAt,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward,fullType,handleScrollToTheMessage,oldId}:IMessageLeftReply) => {
- const classes = useStyles();
- const [anchorEl, setAnchorEl] = useState<any>(null);
- const [selected, setSelected] = useState<boolean>(false);
- const [modal,setModal] = useState<boolean>(false)
- const open = Boolean(anchorEl);
- const checked = isSelected(_id)
-
- const handleClose = (type: string | undefined): void => {
- if (type === 'copy') copied('Message')
- if (type === 'delete') setModal(true)
- setAnchorEl(null)
- setSelected(false)
- }
- const handleDeleteModal = (e: any) => {
- const id = e.target.id
- if (id === 'overlay' || id === 'cancel') return setModal(false)
- if (id === 'delete') {
- removeMessageById(_id)
- setModal(false)
- }
- }
- const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
- e.preventDefault()
- setAnchorEl(e.currentTarget)
- setSelected(true)
- }
- const handleEmojiMenu = ({ target }: any): void => {
- const idEmoji = target.id
- if (idEmoji === emoji) {updateMessageById(_id,'')
- } else updateMessageById(_id,idEmoji)
- }
-
- const handleClickIcon = (e: any) => {
- e.stopPropagation()
- handleDownload(url, fullType)
- }
-
- return (
- <div className={classes.container}>
- <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
- style={{backgroundColor:selected?'#babdbc':undefined,
- border:selected?'#babdbc':undefined,pointerEvents:isSomeSelected?'none':'auto'}}>
- <Typography style={{marginLeft:55,color: "#42aee0"}} variant="h6" align="right">
- {`${firstLetter(name)}${slicedWord(name, 15, 1)}
- ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
- </Typography>
- <div className={classes.wrapperInner}>
- {fullType === null &&<CopyToClipboard onCopy={() => copied('Message')} text={replyMessage}>
- <ContentCopyIcon className={classes.folderIcon} fontSize='large'/>
- </CopyToClipboard>}
- {fullType&&fullType.includes('audio') &&<LibraryMusicIcon onClick={handleClickIcon}
- className={classes.folderIcon} fontSize='large' />}
- {fullType&&fullType.includes('video') &&<VideoLibraryIcon onClick={handleClickIcon}
- className={classes.folderIcon} fontSize='large' />}
- {fullType&&fullType.includes('image') &&<ImageIcon onClick={handleClickIcon}
- className={classes.folderIcon} fontSize='large' />}
- {fullType&&fullType.includes('application') && <FolderIcon onClick={handleClickIcon}
- className={classes.folderIcon} fontSize='large' />}
- <div className={classes.replyColumn}></div>
- <div className={classes.wrapperInnerMessage}>
- <ListItemText style={{width:'100%'}} onClick={() => handleScrollToTheMessage(oldId)}
- primary={`Replied to ${firstLetter(replyName)}${slicedWord(replyName, 15, 1)}
- ${firstLetter(replyLastName)}${slicedWord(replyLastName, 15, 1)}`}
- primaryTypographyProps={{color: "#00b333"}}
- secondary={replyMessage}
- secondaryTypographyProps={{ color: "#626262" }} />
- {replyCaption&&<ListItemText style={{width:'100%'}} onClick={() => handleScrollToTheMessage(oldId)}
- primary='Caption' primaryTypographyProps={{color: "#00b333"}}
- secondary={replyCaption} secondaryTypographyProps={{ color: "#626262" }}/>}
- </div>
- </div>
- <ListItemText className={selected?classes.messageActive:classes.message}
- primary={message}
- primaryTypographyProps={{color: "#626262"}}/>
- <div className={classes.time}>{timeStampMessage(createdAt)}</div>
- {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
- {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
- {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
- onClick={() => handleSelected(_id)}/></div>}
- <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
- anchorEl={anchorEl} open={open} onClose={handleClose}>
- <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
- {emojisArr.map((el:string, i:number) =>
- <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
- </MenuItem>
- <Divider />
- <MenuItem onClick={() => {
- handleReply(_id)
- handleClose(undefined)
- }}>
- <ReplyIcon />
- Reply
- </MenuItem>
- <MenuItem onClick={() => {
- handleForward(_id)
- handleClose(undefined)
- }}>
- <ReplyIcon style={{transform :'rotateY(180deg)'}} />
- Forward
- </MenuItem>
- <CopyToClipboard onCopy={() => handleClose('copy')} text={message}>
- <MenuItem>
- <ContentCopyIcon />
- Copy Text
- </MenuItem>
- </CopyToClipboard>
- <MenuItem onClick={() => {
- pinMessageById(_id, !pinned)
- handleClose(undefined)
- }}>
- {pinned ?
- <CloseIcon className={classes.iconClose} /> :
- <PushPinIcon />}
- {pinned?'Unpin':'Pin'}
- </MenuItem>
- <MenuItem onClick={() => {
- handleSelected(_id)
- handleClose(undefined)
- }}>
- <CheckBoxIcon />
- Select
- </MenuItem>
- <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
- <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
- Delete
- </MenuItem>
- </StyledMenu>
- {modal &&
- <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
- <div className={classes.modalDelete}>
- <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
- <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
- <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
- DELETE MESSAGE
- </Button>
- <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
- CANCEL
- </Button>
- </div>
- </div>}
- </div>
- {caption&&<div className={classes.captionWrapper}>{caption}</div>}
- </div>
- )};
- export default MessageLeftReply
|