index.tsx 15 KB

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