index.tsx 15 KB

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