index.tsx 16 KB

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