index.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  23. import { firstLetter,slicedWord,timeStampMessage,copied,emojisArr,handleDownload } from '../../../../../../helpers'
  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-start',
  63. alignContent: 'flex-start',
  64. flexDirection:'column',
  65. borderRadius: 7,
  66. position: 'relative',
  67. marginBottom: 5,
  68. padding:'10px 0px 10px 22px'
  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: "#ffffff",
  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 #ffffff",
  114. borderLeft: "15px solid transparent",
  115. borderRight: "15px solid transparent",
  116. bottom: '0px',
  117. left: "-15px"
  118. },
  119. "&:before": {
  120. content: "''",
  121. position: "absolute",
  122. width: "0",
  123. height: "0",
  124. borderBottom: "17px solid #ffffff",
  125. borderLeft: "16px solid transparent",
  126. borderRight: "16px solid transparent",
  127. bottom: "0px",
  128. left: "-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 #babdbc",
  141. borderLeft: "15px solid transparent",
  142. borderRight: "15px solid transparent",
  143. bottom: '0px',
  144. left: "-15px"
  145. },
  146. "&:before": {
  147. content: "''",
  148. position: "absolute",
  149. width: "0",
  150. height: "0",
  151. borderBottom: "17px solid #babdbc",
  152. borderLeft: "16px solid transparent",
  153. borderRight: "16px solid transparent",
  154. bottom: "0px",
  155. left: "-17px"
  156. }
  157. },
  158. copyIcon: {
  159. color: '#b56ff7',
  160. cursor: 'pointer',
  161. marginRight: 7,
  162. '&:hover': {
  163. color: '#9c3bf8',
  164. },
  165. },
  166. time: {
  167. position: "absolute",
  168. fontSize: ".65em",
  169. fontWeight:600,
  170. bottom: 6,
  171. right: 6,
  172. color: '#414141',
  173. padding: 3,
  174. borderRadius: 5,
  175. },
  176. modalDelete: {
  177. background: '#ffffff',
  178. position: 'absolute',
  179. content:'',
  180. width: '20%',
  181. height:'auto',
  182. left: '40%',
  183. bottom: '48.5%',
  184. borderRadius: 10,
  185. padding: 10,
  186. display: 'flex',
  187. flexDirection:'column'
  188. },
  189. overlay: {
  190. position: 'fixed',
  191. top: 0,
  192. left: 0,
  193. width: '100vw',
  194. height: '100vh',
  195. zIndex: 100,
  196. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  197. overflowY: 'hidden',
  198. },
  199. emojiTitle: {
  200. position: "absolute",
  201. fontSize: "1.7em",
  202. fontWeight:600,
  203. bottom: '0.2rem',
  204. right: -40,
  205. },
  206. emojiCompanionTitle: {
  207. position: "absolute",
  208. fontSize: "1.7em",
  209. fontWeight:600,
  210. bottom: '2.2rem',
  211. right: -40,
  212. },
  213. emoji: {
  214. cursor: 'pointer',
  215. fontSize: '1.7rem',
  216. transition: 'all 0.3s',
  217. '&:hover': {
  218. transform: 'scale(1.5)'
  219. }
  220. },
  221. emojiActive: {
  222. cursor: 'pointer',
  223. fontSize: '1.2rem',
  224. animation: `$emoji 0.6s ease-out`,
  225. animationDirection: 'forwards',
  226. animationIterationCount: 1,
  227. },
  228. '@keyframes emoji': {
  229. '5%': { transform: 'translateY(1rem)'},
  230. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  231. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  232. '80%': {opacity: 0},
  233. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  234. },
  235. iconClose: {
  236. '&:hover': {
  237. transform: 'rotate(180deg)',
  238. transition: 'all 250ms ease-out ',
  239. }
  240. },
  241. folderIcon: {
  242. color: '#00b333',
  243. cursor: 'pointer',
  244. '&:hover': {
  245. color: '#00e040'
  246. },
  247. },
  248. replyListItem: {
  249. display: 'flex',
  250. width: '100%',
  251. flexWrap: 'nowrap',
  252. alignContent: 'center',
  253. alignItems: 'center',
  254. },
  255. checkboxSelect: {
  256. position: 'absolute',
  257. left: -64,
  258. bottom: -10,
  259. pointerEvents: 'auto'
  260. },
  261. replyColumn: {
  262. position: 'absolute',
  263. content: '',
  264. width: 2,
  265. left:43,
  266. top:'10%',
  267. height:'80%',
  268. backgroundColor: '#00b333',
  269. },
  270. });
  271. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  272. interface IMessageLeftReply {
  273. url:string,
  274. replyMessage: string,
  275. message: string,
  276. name: string,
  277. lastName: string,
  278. replyName:string,
  279. replyLastName: string,
  280. replyCaption: string,
  281. createdAt: string,
  282. caption: string,
  283. emoji: string,
  284. emojiCompanion: string,
  285. pinned: boolean,
  286. isSomeSelected: boolean,
  287. isSelected:(_id:string) => boolean,
  288. handleSelected: (_id:string) => void,
  289. _id: string,
  290. nightMode: boolean,
  291. handleReply: (_id: string) => void,
  292. handleForward: (_id: string) => void,
  293. fullType: string,
  294. handleScrollToTheMessage: (_id: string) => void,
  295. oldId: string
  296. }
  297. 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) => {
  298. const classes = useStyles();
  299. const [anchorEl, setAnchorEl] = useState<any>(null);
  300. const [selected, setSelected] = useState<boolean>(false);
  301. const [modal,setModal] = useState<boolean>(false)
  302. const open = Boolean(anchorEl);
  303. const checked = isSelected(_id)
  304. const handleClose = (type: string | undefined): void => {
  305. if (type === 'copy') copied('Message')
  306. if (type === 'delete') setModal(true)
  307. setAnchorEl(null)
  308. setSelected(false)
  309. }
  310. const handleDeleteModal = (e: any) => {
  311. const id = e.target.id
  312. if (id === 'overlay' || id === 'cancel') return setModal(false)
  313. if (id === 'delete') {
  314. removeMessageById(_id)
  315. setModal(false)
  316. }
  317. }
  318. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  319. e.preventDefault()
  320. setAnchorEl(e.currentTarget)
  321. setSelected(true)
  322. }
  323. const handleEmojiMenu = ({ target }: any): void => {
  324. const idEmoji = target.id
  325. if (idEmoji === emoji) {updateMessageById(_id,'')
  326. } else updateMessageById(_id,idEmoji)
  327. }
  328. const handleClickIcon = (e: any) => {
  329. e.stopPropagation()
  330. handleDownload(url, fullType)
  331. }
  332. return (
  333. <div className={classes.container}>
  334. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  335. style={{backgroundColor:selected?'#babdbc':undefined,pointerEvents:isSomeSelected?'none':'auto'}}>
  336. <Typography style={{color: "#42aee0"}} variant="h6" align="right">
  337. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  338. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  339. </Typography>
  340. <div className={classes.wrapperInner}>
  341. {fullType === null &&<CopyToClipboard onCopy={() => copied('Message')} text={`Message: ${replyMessage} , Caption: ${replyCaption}`}>
  342. <ContentCopyIcon className={classes.folderIcon} fontSize='large'/>
  343. </CopyToClipboard>}
  344. {fullType&&fullType.includes('audio') &&<LibraryMusicIcon onClick={handleClickIcon}
  345. className={classes.folderIcon} fontSize='large' />}
  346. {fullType&&fullType.includes('video') &&<VideoLibraryIcon onClick={handleClickIcon}
  347. className={classes.folderIcon} fontSize='large' />}
  348. {fullType&&fullType.includes('image') &&<ImageIcon onClick={handleClickIcon}
  349. className={classes.folderIcon} fontSize='large' />}
  350. {fullType&&fullType.includes('application') && <FolderIcon onClick={handleClickIcon}
  351. className={classes.folderIcon} fontSize='large' />}
  352. <div className={classes.replyColumn}></div>
  353. <div className={classes.wrapperInnerMessage}>
  354. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  355. {`Replied to ${firstLetter(replyName)}${slicedWord(replyName, 15, 1)}
  356. ${firstLetter(replyLastName)}${slicedWord(replyLastName, 15, 1)}`}
  357. </Typography>
  358. <ListItemText style={{width:'100%'}} onClick={() => handleScrollToTheMessage(oldId)}
  359. primary='Message' primaryTypographyProps={{color: "#00b333"}}
  360. secondary={replyMessage} secondaryTypographyProps={{ color: "#626262" }} />
  361. {replyCaption&&<ListItemText style={{width:'100%'}} onClick={() => handleScrollToTheMessage(oldId)}
  362. primary='Caption' primaryTypographyProps={{color: "#00b333"}}
  363. secondary={replyCaption} secondaryTypographyProps={{ color: "#626262" }}/>}
  364. </div>
  365. </div>
  366. <div className={selected?classes.messageActive:classes.message}>
  367. <ListItemText primary='Message' primaryTypographyProps={{ color: "#42aee0" }}
  368. secondary={message} secondaryTypographyProps={{ color: "#2f2f2f" }} />
  369. {caption && <ListItemText primary='Caption' primaryTypographyProps={{ color: "#42aee0" }}
  370. secondary={caption} secondaryTypographyProps={{ color: "#2f2f2f" }}/>}
  371. </div>
  372. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  373. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  374. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  375. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  376. onClick={() => handleSelected(_id)}/></div>}
  377. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  378. anchorEl={anchorEl} open={open} onClose={handleClose}>
  379. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  380. {emojisArr.map((el:string, i:number) =>
  381. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  382. </MenuItem>
  383. <Divider />
  384. <MenuItem onClick={() => {
  385. handleReply(_id)
  386. handleClose(undefined)
  387. }}>
  388. <ReplyIcon />
  389. Reply
  390. </MenuItem>
  391. <MenuItem onClick={() => {
  392. handleForward(_id)
  393. handleClose(undefined)
  394. }}>
  395. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  396. Forward
  397. </MenuItem>
  398. <CopyToClipboard onCopy={() => handleClose('copy')} text={`Message: ${message} , Caption: ${caption}`}>
  399. <MenuItem>
  400. <ContentCopyIcon />
  401. Copy Text
  402. </MenuItem>
  403. </CopyToClipboard>
  404. <MenuItem onClick={() => {
  405. pinMessageById(_id, !pinned)
  406. handleClose(undefined)
  407. }}>
  408. {pinned ?
  409. <CloseIcon className={classes.iconClose} /> :
  410. <PushPinIcon />}
  411. {pinned?'Unpin':'Pin'}
  412. </MenuItem>
  413. <MenuItem onClick={() => {
  414. handleSelected(_id)
  415. handleClose(undefined)
  416. }}>
  417. <CheckBoxIcon />
  418. Select
  419. </MenuItem>
  420. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  421. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  422. Delete
  423. </MenuItem>
  424. </StyledMenu>
  425. {modal &&
  426. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  427. <div className={classes.modalDelete}>
  428. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  429. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  430. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  431. DELETE MESSAGE
  432. </Button>
  433. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  434. CANCEL
  435. </Button>
  436. </div>
  437. </div>}
  438. </div>
  439. </div>
  440. )};
  441. export default MessageLeftReply