index.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { styled } from '@mui/material/styles';
  3. import { useState, useRef } from "react";
  4. import Typography from '@mui/material/Typography';
  5. import DownloadForOfflineIcon from '@mui/icons-material/DownloadForOffline';
  6. import ImageIcon from '@mui/icons-material/Image';
  7. import Button from '@mui/material/Button';
  8. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  9. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  10. import Menu from '@mui/material/Menu';
  11. import MenuItem from '@mui/material/MenuItem';
  12. import Divider from '@mui/material/Divider';
  13. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  14. import Checkbox from '@mui/material/Checkbox';
  15. import PushPinIcon from '@mui/icons-material/PushPin';
  16. import ListItemText from '@mui/material/ListItemText';
  17. import ListItemIcon from '@mui/material/ListItemIcon';
  18. import ZoomOutIcon from '@mui/icons-material/ZoomOut';
  19. import ZoomInIcon from '@mui/icons-material/ZoomIn';
  20. import CloseIcon from '@mui/icons-material/Close';
  21. import ReplyIcon from '@mui/icons-material/Reply';
  22. import DownloadIcon from '@mui/icons-material/Download';
  23. import VisibilityIcon from '@mui/icons-material/Visibility';
  24. import Avatar from '@mui/material/Avatar';
  25. import { CopyToClipboard } from 'react-copy-to-clipboard';
  26. import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  27. import { timeStampMessage, timeStampEU,handleDownload,copied,emojisArr,firstLetter, slicedWord,prodAwsS3 } from '../../../../../../helpers'
  28. const StyledMenu = styled((props:any) => (
  29. <Menu
  30. elevation={0}
  31. anchorOrigin={{
  32. vertical: 'top',
  33. horizontal: 'right',
  34. }}
  35. transformOrigin={{
  36. vertical: 'bottom',
  37. horizontal: 'right',
  38. }}
  39. {...props}
  40. />
  41. ))(({ theme }:any) => ({
  42. '& .MuiPaper-root': {
  43. borderRadius: 10,
  44. marginTop: theme.spacing(0),
  45. minWidth: 220,
  46. color:
  47. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  48. boxShadow:
  49. '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',
  50. '& .MuiMenu-list': {
  51. padding: '4px 4px',
  52. },
  53. '& .MuiMenuItem-root': {
  54. marginBottom: theme.spacing(1),
  55. '& .MuiSvgIcon-root': {
  56. fontSize: 21,
  57. color: theme.palette.text.secondary,
  58. marginRight: theme.spacing(2),
  59. }
  60. },
  61. },
  62. }));
  63. const useStyles = makeStyles({
  64. container: {
  65. display: "flex",
  66. alignItems: 'flex-start',
  67. alignContent: 'flex-start',
  68. flexDirection:'column',
  69. borderRadius: 7,
  70. position: 'relative',
  71. padding:'4px 0px 4px 22px'
  72. },
  73. wrapper: {
  74. position: 'relative',
  75. display: 'flex',
  76. alignItems: 'start',
  77. alignContent: 'start',
  78. flexDirection: 'column',
  79. width: 400,
  80. borderRadius: 7,
  81. padding: 5,
  82. },
  83. wrapperInner: {
  84. display: 'flex',
  85. alignItems: 'center',
  86. alignContent: 'center',
  87. },
  88. informationWrapper: {
  89. display: 'flex',
  90. alignItems: 'center',
  91. alignContent: 'center',
  92. justifyContent: 'flex-end',
  93. width: '100%',
  94. paddingRight:3,
  95. },
  96. time: {
  97. fontSize: ".65em",
  98. fontWeight:600,
  99. color: '#414141',
  100. },
  101. image: {
  102. borderRadius: 7,
  103. width: 348,
  104. maxHeight: 'auto',
  105. cursor: 'pointer',
  106. padding: '10px 0px 10px 0px',
  107. },
  108. bntDownload: {
  109. backgroundColor: 'inherit',
  110. color: '#54b0fc',
  111. width: 30,
  112. height:30,
  113. '&:hover': {
  114. backgroundColor: '#54b0fc',
  115. color:'#ffffff'
  116. }
  117. },
  118. overlay: {
  119. position: 'fixed',
  120. top: 0,
  121. left: 0,
  122. width: '100vw',
  123. minHeight: '100vh',
  124. zIndex: 100,
  125. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  126. overflow: 'auto',
  127. boxSizing: 'border-box',
  128. display: 'flex',
  129. justifyContent: 'center',
  130. alignContent: 'center',
  131. alignItems: 'center'
  132. },
  133. topBar: {
  134. position: 'fixed',
  135. top: 0,
  136. left: 0,
  137. height: '7vh',
  138. width: '100vw',
  139. display: 'flex',
  140. alignContent: 'center',
  141. alignItems: 'center',
  142. justifyContent: 'space-between',
  143. backgroundColor: 'rgba(65, 65, 65, 0.9)',
  144. zIndex: 10,
  145. padding: '0px 20px'
  146. },
  147. wrapperCredentials: {
  148. display: 'flex',
  149. alignContent: 'center',
  150. alignItems: 'center',
  151. },
  152. wrapperIcons: {
  153. display: 'flex',
  154. alignContent: 'center',
  155. alignItems: 'center',
  156. },
  157. magnifying : {
  158. marginLeft:5,
  159. cursor: 'pointer',
  160. color: '#e9e7e7',
  161. padding: 0,
  162. '&:hover': {
  163. color: '#ffffff',
  164. transform: 'scale(1.1)'
  165. }
  166. },
  167. downloadIcon: {
  168. marginLeft:5,
  169. cursor: 'pointer',
  170. color: '#e9e7e7',
  171. padding: 0,
  172. borderRadius: '50%',
  173. '&:hover': {
  174. backgroundColor: '#ffffff',
  175. color: '#b8b7b7',
  176. }
  177. },
  178. iconCloseOverlay: {
  179. marginLeft:5,
  180. cursor: 'pointer',
  181. color: '#e9e7e7',
  182. padding: 0,
  183. '&:hover': {
  184. color: '#ffffff',
  185. transform: 'rotate(180deg)',
  186. transition: 'all 250ms ease-out ',
  187. }
  188. },
  189. wrapperImage: {
  190. borderRadius: 5,
  191. maxWidth:500,
  192. maxHeight: 750,
  193. display: 'flex',
  194. overflow: 'auto'
  195. },
  196. innerImage: {
  197. objectFit: 'cover',
  198. },
  199. modalDelete: {
  200. background: '#ffffff',
  201. position: 'absolute',
  202. content:'',
  203. width: '20%',
  204. height:'auto',
  205. left: '40%',
  206. bottom: '48.5%',
  207. borderRadius: 10,
  208. padding: 10,
  209. display: 'flex',
  210. flexDirection:'column'
  211. },
  212. overlayDelete: {
  213. position: 'fixed',
  214. top: 0,
  215. left: 0,
  216. width: '100vw',
  217. height: '100vh',
  218. zIndex: 100,
  219. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  220. overflowY: 'hidden',
  221. },
  222. emojiTitle: {
  223. position: "absolute",
  224. fontSize: "1.7em",
  225. fontWeight:600,
  226. bottom: '0.2rem',
  227. right: -40,
  228. },
  229. emojiCompanionTitle: {
  230. position: "absolute",
  231. fontSize: "1.7em",
  232. fontWeight:600,
  233. bottom: '2.2rem',
  234. right: -40,
  235. },
  236. emoji: {
  237. cursor: 'pointer',
  238. fontSize: '1.7rem',
  239. transition: 'all 0.3s',
  240. '&:hover': {
  241. transform: 'scale(1.5)'
  242. }
  243. },
  244. emojiActive: {
  245. cursor: 'pointer',
  246. fontSize: '1.2rem',
  247. animation: `$emoji 0.6s ease-out`,
  248. animationDirection: 'forwards',
  249. animationIterationCount: 1,
  250. },
  251. '@keyframes emoji': {
  252. '5%': { transform: 'translateY(1rem)'},
  253. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  254. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  255. '80%': {opacity: 0},
  256. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  257. },
  258. iconClose: {
  259. '&:hover': {
  260. transform: 'rotate(180deg)',
  261. transition: 'all 250ms ease-out ',
  262. }
  263. },
  264. checkboxSelect: {
  265. position: 'absolute',
  266. left: -64,
  267. top: -10,
  268. pointerEvents: 'auto'
  269. },
  270. folderIcon: {
  271. marginRight: 7,
  272. color: '#54b0fc',
  273. cursor: 'pointer',
  274. '&:hover': {
  275. color: '#016cc3'
  276. },
  277. },
  278. avatarIcon: {
  279. position: 'absolute',
  280. left: -54,
  281. bottom: 0,
  282. },
  283. tongueOne: {
  284. content: "''",
  285. position: "absolute",
  286. width: "0",
  287. height: "0",
  288. borderLeft: "15px solid transparent",
  289. borderRight: "15px solid transparent",
  290. bottom: '0px',
  291. left: "-15px",
  292. },
  293. tongueTwo: {
  294. content: "''",
  295. position: "absolute",
  296. width: "0",
  297. height: "0",
  298. borderLeft: "16px solid transparent",
  299. borderRight: "16px solid transparent",
  300. bottom: "0px",
  301. left: "-17px",
  302. },
  303. });
  304. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  305. interface IMessagesLeftImage {
  306. url: string,
  307. tongue: boolean,
  308. watched: boolean,
  309. edited: boolean,
  310. avatarUrl: string,
  311. color: string,
  312. createdAt:string,
  313. fullType: string,
  314. caption: string,
  315. emoji: string,
  316. emojiCompanion: string,
  317. pinned: boolean,
  318. isSomeSelected: boolean,
  319. isSelected:(_id:string) => boolean,
  320. handleSelected: (_id:string) => void,
  321. _id: string,
  322. name: string,
  323. lastName: string,
  324. nightMode: boolean,
  325. handleReply: (_id: string) => void,
  326. handleForward: (_id: string) => void,
  327. }
  328. const MessagesLeftImage = ({url,tongue,watched,edited,avatarUrl,color,createdAt,fullType,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,name,lastName,nightMode,handleReply,handleForward}:IMessagesLeftImage) => {
  329. const classes = useStyles();
  330. const [watch, setWatch] = useState<boolean>(false)
  331. const [anchorEl, setAnchorEl] = useState<any>(null);
  332. const [selected, setSelected] = useState<boolean>(false);
  333. const [scale, setScale] = useState<number>(1)
  334. const refView = useRef<null | any>(null)
  335. const [modal,setModal] = useState<boolean>(false)
  336. const open = Boolean(anchorEl);
  337. const checked = isSelected(_id)
  338. const handleIncreaseScale = () => {
  339. if (scale < 5) {
  340. refView.current.style.transform = `scale(${scale+0.25},${scale+0.25})`
  341. refView.current.style.transformOrigin = `${50 / scale + 0.25}px ${50 / scale + 0.25}px`
  342. setScale(scale+0.25)
  343. }
  344. }
  345. const handleDecreaseScale = () => {
  346. if (scale >= 0.5) {
  347. refView.current.style.transform = `scale(${scale-0.25},${scale-0.25})`
  348. refView.current.style.transformOrigin = `${50/scale-0.25}px ${50/scale-0.25}px`
  349. setScale(scale-0.25)
  350. }
  351. }
  352. const handleOpenWatch = () => !watch&&setWatch(true)
  353. const handleCloseWatch = (e:any) => {
  354. const id = e.target.id
  355. if (id === 'overlay' || id === 'close') {
  356. setWatch(false)
  357. refView.current.style.transform = 'scale(1)'
  358. setScale(1)
  359. }
  360. }
  361. const handleClose = (type: string | undefined): void => {
  362. if (type === 'copy') copied('Link')
  363. if (type === 'delete') setModal(true)
  364. setAnchorEl(null)
  365. setSelected(false)
  366. }
  367. const handleDeleteModal = (e: any) => {
  368. const id = e.target.id
  369. if (id === 'overlay' || id === 'cancel') return setModal(false)
  370. if (id === 'delete') {
  371. removeMessageById(_id)
  372. setModal(false)
  373. }
  374. }
  375. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  376. e.preventDefault()
  377. setAnchorEl(e.currentTarget)
  378. setSelected(true)
  379. }
  380. const handleEmojiMenu = ({ target }: any): void => {
  381. const idEmoji = target.id
  382. if (idEmoji === emoji) {updateMessageById(_id,'')
  383. } else updateMessageById(_id,idEmoji)
  384. }
  385. return (watch ?
  386. <div onClick={handleCloseWatch} id='overlay' className={classes.overlay}>
  387. <div className={classes.topBar}>
  388. <div className={classes.wrapperCredentials}>
  389. <ListItemIcon >
  390. <Avatar alt={name} src={url?url:undefined}
  391. sx={{ background: color, width: 44, height: 44 }}>
  392. {!url&&`${firstLetter(name)}${firstLetter(lastName)}`}
  393. </Avatar>
  394. </ListItemIcon>
  395. <ListItemText primary={`${firstLetter(name)}${slicedWord(name, 15, 1)}
  396. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  397. primaryTypographyProps={{ color: '#ffffff' }}
  398. secondary={timeStampEU(createdAt)} secondaryTypographyProps={{ color: '#ffffff' }} />
  399. </div>
  400. <div className={classes.wrapperIcons}>
  401. <ZoomOutIcon onClick={handleDecreaseScale}
  402. className={classes.magnifying} fontSize='large' />
  403. <ZoomInIcon onClick={handleIncreaseScale}
  404. className={classes.magnifying} fontSize='large' />
  405. <DownloadForOfflineIcon onClick={() => handleDownload(url, fullType)}
  406. className={classes.downloadIcon} fontSize='large' />
  407. <CloseIcon id='close' onClick={handleCloseWatch}
  408. className={classes.iconCloseOverlay} fontSize='large' />
  409. </div>
  410. </div>
  411. <div ref={refView} className={classes.wrapperImage}>
  412. <img className={classes.innerImage}
  413. width='100%' height='auto' alt='imageItem' src={url} />
  414. </div>
  415. </div> :
  416. <div className={classes.container} style={{marginBottom:tongue?12:0}}>
  417. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  418. style={{backgroundColor:selected?'#babdbc':'#ffffff',pointerEvents:isSomeSelected?'none':'auto'}}>
  419. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  420. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  421. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  422. </Typography>
  423. <div className={classes.wrapperInner}>
  424. <ImageIcon onClick={() => handleDownload(url, fullType)}
  425. className={classes.folderIcon} fontSize='large' />
  426. <img onClick={handleOpenWatch} className={classes.image} alt='message pic' src={url}
  427. style={{ backgroundColor: url ? '' : color }} width='300' height='400' />
  428. </div>
  429. <ListItemText style={{wordBreak:'break-word'}} secondary={caption} secondaryTypographyProps={{color: "#000000"}}/>
  430. <div className={classes.informationWrapper}>
  431. <div className={classes.time} style={{ color: '#959595'}}>{`${edited?'edited ':''}${timeStampMessage(createdAt)}`}</div>
  432. {watched&&<VisibilityIcon style={{ color: '#959595', marginLeft: 5 }} fontSize='small' />}
  433. </div>
  434. {tongue&&<div className={classes.avatarIcon}>
  435. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  436. sx={{ background: color, width: 40, height: 40 }}>
  437. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  438. </Avatar>
  439. </div>}
  440. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  441. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  442. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  443. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  444. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  445. onClick={() => handleSelected(_id)}/></div>}
  446. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  447. anchorEl={anchorEl} open={open} onClose={handleClose}>
  448. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  449. {emojisArr.map((el:string, i:number) =>
  450. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  451. </MenuItem>
  452. <Divider />
  453. <MenuItem onClick={() => {
  454. handleReply(_id)
  455. handleClose(undefined)
  456. }}>
  457. <ReplyIcon />
  458. Reply
  459. </MenuItem>
  460. <MenuItem onClick={() => {
  461. handleForward(_id)
  462. handleClose(undefined)
  463. }}>
  464. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  465. Forward
  466. </MenuItem>
  467. <MenuItem onClick={() => handleDownload(url, fullType)}>
  468. <DownloadIcon/>
  469. Download
  470. </MenuItem>
  471. <CopyToClipboard onCopy={() => handleClose('copy')} text={url}>
  472. <MenuItem>
  473. <ContentCopyIcon />
  474. Copy Link
  475. </MenuItem>
  476. </CopyToClipboard>
  477. <MenuItem onClick={() => {
  478. pinMessageById(_id, !pinned)
  479. handleClose(undefined)
  480. }}>
  481. {pinned ?
  482. <CloseIcon className={classes.iconClose} /> :
  483. <PushPinIcon />}
  484. {pinned?'Unpin':'Pin'}
  485. </MenuItem>
  486. <MenuItem onClick={() => {
  487. handleSelected(_id)
  488. handleClose(undefined)
  489. }}>
  490. <CheckBoxIcon />
  491. Select
  492. </MenuItem>
  493. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  494. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  495. Delete
  496. </MenuItem>
  497. </StyledMenu>
  498. {modal &&
  499. <div onClick={handleDeleteModal} className={classes.overlayDelete} id='overlay'>
  500. <div className={classes.modalDelete}>
  501. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  502. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  503. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  504. DELETE MESSAGE
  505. </Button>
  506. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  507. CANCEL
  508. </Button>
  509. </div>
  510. </div>}
  511. </div>
  512. </div>)
  513. };
  514. export default MessagesLeftImage