index.tsx 14 KB

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