index.tsx 14 KB

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