index.tsx 14 KB

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