index.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { styled } from '@mui/material/styles';
  3. import { useState } from "react";
  4. import Typography from '@mui/material/Typography';
  5. import ListItemText from '@mui/material/ListItemText';
  6. import Button from '@mui/material/Button';
  7. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  8. import Menu from '@mui/material/Menu';
  9. import MenuItem from '@mui/material/MenuItem';
  10. import Divider from '@mui/material/Divider';
  11. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  12. import Checkbox from '@mui/material/Checkbox';
  13. import PushPinIcon from '@mui/icons-material/PushPin';
  14. import CloseIcon from '@mui/icons-material/Close';
  15. import ReplyIcon from '@mui/icons-material/Reply';
  16. import LibraryMusicIcon from '@mui/icons-material/LibraryMusic';
  17. import FolderIcon from '@mui/icons-material/Folder';
  18. import ImageIcon from '@mui/icons-material/Image';
  19. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  20. import VideoLibraryIcon from '@mui/icons-material/VideoLibrary';
  21. import { CopyToClipboard } from 'react-copy-to-clipboard';
  22. import { firstLetter, slicedWord, timeStampMessage, copied,emojisArr,handleDownload } from '../../../../../../helpers'
  23. import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  24. const StyledMenu = styled((props:any) => (
  25. <Menu
  26. elevation={0}
  27. anchorOrigin={{
  28. vertical: 'top',
  29. horizontal: 'right',
  30. }}
  31. transformOrigin={{
  32. vertical: 'bottom',
  33. horizontal: 'right',
  34. }}
  35. {...props}
  36. />
  37. ))(({ theme }:any) => ({
  38. '& .MuiPaper-root': {
  39. borderRadius: 10,
  40. marginTop: theme.spacing(0),
  41. minWidth: 220,
  42. color:
  43. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  44. boxShadow:
  45. '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',
  46. '& .MuiMenu-list': {
  47. padding: '4px 4px',
  48. },
  49. '& .MuiMenuItem-root': {
  50. marginBottom: theme.spacing(1),
  51. '& .MuiSvgIcon-root': {
  52. fontSize: 21,
  53. color: theme.palette.text.secondary,
  54. marginRight: theme.spacing(2),
  55. }
  56. },
  57. },
  58. }));
  59. const useStyles = makeStyles({
  60. container: {
  61. display: "flex",
  62. alignItems: 'flex-end',
  63. alignContent: 'flex-end',
  64. flexDirection:'column',
  65. borderRadius: 7,
  66. position: 'relative',
  67. marginBottom: 5,
  68. padding:'10px 22px 10px 0px'
  69. },
  70. wrapper: {
  71. position: 'relative',
  72. display: 'flex',
  73. alignItems: 'center',
  74. alignContent: 'center',
  75. flexWrap: 'wrap',
  76. maxWidth: 450,
  77. minWidth:200,
  78. padding: "10px",
  79. paddingBottom:18,
  80. backgroundColor: "#deffa9",
  81. borderRadius: 7,
  82. },
  83. wrapperInner: {
  84. position:'relative',
  85. display: 'flex',
  86. alignItems: 'center',
  87. alignContent: 'center',
  88. width: '100%',
  89. cursor: 'pointer',
  90. '&:hover': {
  91. backgroundColor: 'rgba(104, 105, 104, 0.2)'
  92. }
  93. },
  94. wrapperInnerMessage: {
  95. display: 'flex',
  96. alignItems: 'center',
  97. alignContent: 'center',
  98. flexWrap: 'wrap',
  99. marginLeft:20,
  100. wordBreak:'break-word',
  101. textAlign: "left",
  102. font: "400 .9em 'Open Sans', sans-serif",
  103. },
  104. message: {
  105. wordBreak:'break-word',
  106. textAlign: "left",
  107. font: "400 .9em 'Open Sans', sans-serif",
  108. "&:after": {
  109. content: "''",
  110. position: "absolute",
  111. width: "0",
  112. height: "0",
  113. borderBottom: "15px solid #deffa9",
  114. borderLeft: "15px solid transparent",
  115. borderRight: "15px solid transparent",
  116. bottom: "0px",
  117. right: "-15px"
  118. },
  119. "&:before": {
  120. content: "''",
  121. position: "absolute",
  122. width: "0",
  123. height: "0",
  124. borderBottom: "17px solid #deffa9",
  125. borderLeft: "16px solid transparent",
  126. borderRight: "16px solid transparent",
  127. bottom: "0px",
  128. right: "-17px"
  129. },
  130. },
  131. messageActive: {
  132. wordBreak:'break-word',
  133. textAlign: "left",
  134. font: "400 .9em 'Open Sans', sans-serif",
  135. "&:after": {
  136. content: "''",
  137. position: "absolute",
  138. width: "0",
  139. height: "0",
  140. borderBottom: "15px solid #ced8d7",
  141. borderLeft: "15px solid transparent",
  142. borderRight: "15px solid transparent",
  143. bottom: "0",
  144. right: "-15px"
  145. },
  146. "&:before": {
  147. content: "''",
  148. position: "absolute",
  149. width: "0",
  150. height: "0",
  151. borderBottom: "17px solid #ced8d7",
  152. borderLeft: "16px solid transparent",
  153. borderRight: "16px solid transparent",
  154. bottom: "0px",
  155. right: "-17px"
  156. }
  157. },
  158. time: {
  159. position: "absolute",
  160. fontSize: ".65em",
  161. fontWeight:600,
  162. bottom: 6,
  163. right: 6,
  164. color: '#414141',
  165. padding: 3,
  166. borderRadius: 5,
  167. },
  168. modalDelete: {
  169. background: '#ffffff',
  170. position: 'absolute',
  171. content:'',
  172. width: '20%',
  173. height:'auto',
  174. left: '40%',
  175. bottom: '48.5%',
  176. borderRadius: 10,
  177. padding: 10,
  178. display: 'flex',
  179. flexDirection:'column'
  180. },
  181. overlay: {
  182. position: 'fixed',
  183. top: 0,
  184. left: 0,
  185. width: '100vw',
  186. height: '100vh',
  187. zIndex: 100,
  188. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  189. overflowY: 'hidden',
  190. },
  191. emojiTitle: {
  192. position: "absolute",
  193. fontSize: "1.7em",
  194. fontWeight:600,
  195. bottom: '0.2rem',
  196. left: -40,
  197. },
  198. emojiCompanionTitle: {
  199. position: "absolute",
  200. fontSize: "1.7em",
  201. fontWeight:600,
  202. bottom: '2.2rem',
  203. left: -40,
  204. },
  205. emoji: {
  206. cursor: 'pointer',
  207. fontSize: '1.7rem',
  208. transition: 'all 0.3s',
  209. '&:hover': {
  210. transform: 'scale(1.5)'
  211. }
  212. },
  213. emojiActive: {
  214. cursor: 'pointer',
  215. fontSize: '1.2rem',
  216. animation: `$emoji 0.6s ease-out`,
  217. animationDirection: 'forwards',
  218. animationIterationCount: 1,
  219. },
  220. '@keyframes emoji': {
  221. '5%': { transform: 'translateY(1rem)'},
  222. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  223. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  224. '80%': {opacity: 0},
  225. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  226. },
  227. iconClose: {
  228. '&:hover': {
  229. transform: 'rotate(180deg)',
  230. transition: 'all 250ms ease-out ',
  231. }
  232. },
  233. folderIcon: {
  234. color: '#00b333',
  235. cursor: 'pointer',
  236. '&:hover': {
  237. color: '#00e040'
  238. },
  239. },
  240. checkboxSelect: {
  241. position: 'absolute',
  242. right: -64,
  243. bottom: -10,
  244. pointerEvents: 'auto'
  245. },
  246. replyColumn: {
  247. position: 'absolute',
  248. content: '',
  249. width: 2,
  250. left:43,
  251. top:'10%',
  252. height:'80%',
  253. backgroundColor: '#00b333',
  254. },
  255. tittle: {
  256. margin:0,
  257. }
  258. });
  259. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  260. interface IMessageRightReply {
  261. url:string,
  262. replyMessage: string,
  263. message: string,
  264. name: string,
  265. lastName: string,
  266. replyName:string,
  267. replyLastName: string,
  268. replyCaption: string,
  269. createdAt: string,
  270. caption: string,
  271. emoji: string,
  272. emojiCompanion: string,
  273. pinned: boolean,
  274. isSomeSelected: boolean,
  275. isSelected:(_id:string) => boolean,
  276. handleSelected: (_id:string) => void,
  277. _id: string,
  278. nightMode: boolean,
  279. handleReply: (_id: string) => void,
  280. handleForward: (_id: string) => void,
  281. fullType: string,
  282. handleScrollToTheMessage: (_id: string) => void,
  283. oldId: string
  284. }
  285. const MessageRightReply = ({url,replyMessage,message,name,lastName,replyName,replyLastName,replyCaption,createdAt,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward,fullType,handleScrollToTheMessage,oldId}:IMessageRightReply) => {
  286. const classes = useStyles();
  287. const [anchorEl, setAnchorEl] = useState<any>(null);
  288. const [selected, setSelected] = useState<boolean>(false);
  289. const [modal,setModal] = useState<boolean>(false)
  290. const open = Boolean(anchorEl);
  291. const checked = isSelected(_id)
  292. const handleClose = (type: string | undefined): void => {
  293. if (type === 'copy') copied('Message')
  294. if (type === 'delete') setModal(true)
  295. setAnchorEl(null)
  296. setSelected(false)
  297. }
  298. const handleDeleteModal = (e: any) => {
  299. const id = e.target.id
  300. if (id === 'overlay' || id === 'cancel') return setModal(false)
  301. if (id === 'delete') {
  302. removeMessageById(_id)
  303. setModal(false)
  304. }
  305. }
  306. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  307. e.preventDefault()
  308. setAnchorEl(e.currentTarget)
  309. setSelected(true)
  310. }
  311. const handleEmojiMenu = ({ target }: any): void => {
  312. const idEmoji = target.id
  313. if (idEmoji === emoji) {updateMessageById(_id,'')
  314. } else updateMessageById(_id,idEmoji)
  315. }
  316. const handleClickIcon = (e: any) => {
  317. e.stopPropagation()
  318. handleDownload(url, fullType)
  319. }
  320. return (
  321. <div className={classes.container}>
  322. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  323. style={{backgroundColor:selected?'#ced8d7':undefined,pointerEvents:isSomeSelected?'none':'auto'}}>
  324. <Typography style={{color: "#42aee0"}} variant="h6" align="right">
  325. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  326. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  327. </Typography>
  328. <div className={classes.wrapperInner}>
  329. {fullType === null &&<CopyToClipboard onCopy={() => copied('Message')} text={`Message: ${replyMessage} , Caption: ${replyCaption}`}>
  330. <ContentCopyIcon className={classes.folderIcon} fontSize='large'/>
  331. </CopyToClipboard>}
  332. {fullType&&fullType.includes('audio') &&<LibraryMusicIcon onClick={handleClickIcon}
  333. className={classes.folderIcon} fontSize='large' />}
  334. {fullType&&fullType.includes('video') &&<VideoLibraryIcon onClick={handleClickIcon}
  335. className={classes.folderIcon} fontSize='large' />}
  336. {fullType&&fullType.includes('image') &&<ImageIcon onClick={handleClickIcon}
  337. className={classes.folderIcon} fontSize='large' />}
  338. {fullType&&fullType.includes('application') && <FolderIcon onClick={handleClickIcon}
  339. className={classes.folderIcon} fontSize='large' />}
  340. <div className={classes.replyColumn}></div>
  341. <div className={classes.wrapperInnerMessage}>
  342. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  343. {`Replied to ${firstLetter(replyName)}${slicedWord(replyName, 15, 1)}
  344. ${firstLetter(replyLastName)}${slicedWord(replyLastName, 15, 1)}`}
  345. </Typography>
  346. <ListItemText style={{width:'100%'}} onClick={() => handleScrollToTheMessage(oldId)}
  347. primary='Message' primaryTypographyProps={{color: "#00b333"}}
  348. secondary={replyMessage} secondaryTypographyProps={{ color: "#626262" }} />
  349. {replyCaption&&<ListItemText style={{width:'100%'}} onClick={() => handleScrollToTheMessage(oldId)}
  350. primary='Caption' primaryTypographyProps={{color: "#00b333"}}
  351. secondary={replyCaption} secondaryTypographyProps={{ color: "#626262" }}/>}
  352. </div>
  353. </div>
  354. <div className={selected?classes.messageActive:classes.message}>
  355. <ListItemText primary='Message' primaryTypographyProps={{ color: "#42aee0" }}
  356. secondary={message} secondaryTypographyProps={{ color: "#2f2f2f" }} />
  357. {caption && <ListItemText primary='Caption' primaryTypographyProps={{ color: "#42aee0" }}
  358. secondary={caption} secondaryTypographyProps={{ color: "#2f2f2f" }}/>}
  359. </div>
  360. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  361. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  362. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  363. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  364. onClick={() => handleSelected(_id)}/></div>}
  365. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  366. anchorEl={anchorEl} open={open} onClose={handleClose}>
  367. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  368. {emojisArr.map((el:string, i:number) =>
  369. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  370. </MenuItem>
  371. <Divider />
  372. <MenuItem onClick={() => {
  373. handleReply(_id)
  374. handleClose(undefined)
  375. }}>
  376. <ReplyIcon />
  377. Reply
  378. </MenuItem>
  379. <MenuItem onClick={() => {
  380. handleForward(_id)
  381. handleClose(undefined)
  382. }}>
  383. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  384. Forward
  385. </MenuItem>
  386. <CopyToClipboard onCopy={() => handleClose('copy')} text={`Message: ${message} , Caption: ${caption}`}>
  387. <MenuItem>
  388. <ContentCopyIcon />
  389. Copy Text
  390. </MenuItem>
  391. </CopyToClipboard>
  392. <MenuItem onClick={() => {
  393. pinMessageById(_id, !pinned)
  394. handleClose(undefined)
  395. }}>
  396. {pinned ?
  397. <CloseIcon className={classes.iconClose} /> :
  398. <PushPinIcon />}
  399. {pinned?'Unpin':'Pin'}
  400. </MenuItem>
  401. <MenuItem onClick={() => {
  402. handleSelected(_id)
  403. handleClose(undefined)
  404. }}>
  405. <CheckBoxIcon />
  406. Select
  407. </MenuItem>
  408. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  409. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  410. Delete
  411. </MenuItem>
  412. </StyledMenu>
  413. {modal &&
  414. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  415. <div className={classes.modalDelete}>
  416. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  417. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  418. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  419. DELETE MESSAGE
  420. </Button>
  421. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  422. CANCEL
  423. </Button>
  424. </div>
  425. </div>}
  426. </div>
  427. </div>
  428. )};
  429. export default MessageRightReply