index.tsx 14 KB

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