index.tsx 17 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 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. edited: boolean,
  301. avatarUrl: string,
  302. color: string,
  303. createdAt:string,
  304. fullType: string,
  305. caption: string,
  306. emoji: string,
  307. emojiCompanion: string,
  308. pinned: boolean,
  309. isSomeSelected: boolean,
  310. isSelected:(_id:string) => boolean,
  311. handleSelected: (_id:string) => void,
  312. _id: string,
  313. name: string,
  314. lastName: string,
  315. nightMode: boolean,
  316. handleReply: (_id: string) => void,
  317. handleForward: (_id: string) => void,
  318. handleEdit:(_id: string) => void,
  319. }
  320. const MessageRightImage = ({url,tongue,watched,edited,avatarUrl,color,createdAt,fullType,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,name,lastName,nightMode,handleReply,handleForward,handleEdit}:IMessageRightImage) => {
  321. const classes = useStyles();
  322. const [watch, setWatch] = useState<boolean>(false)
  323. const [anchorEl, setAnchorEl] = useState<any>(null);
  324. const [selected, setSelected] = useState<boolean>(false);
  325. const [modal, setModal] = useState<boolean>(false)
  326. const [scale, setScale] = useState<number>(1)
  327. const refView = useRef<null | any>(null)
  328. const open = Boolean(anchorEl);
  329. const checked = isSelected(_id)
  330. const handleIncreaseScale = () => {
  331. if (scale < 5) {
  332. refView.current.style.transform = `scale(${scale+0.25},${scale+0.25})`
  333. refView.current.style.transformOrigin = `${50 / scale + 0.25}px ${50 / scale + 0.25}px`
  334. setScale(scale+0.25)
  335. }
  336. }
  337. const handleDecreaseScale = () => {
  338. if (scale >= 0.5) {
  339. refView.current.style.transform = `scale(${scale-0.25},${scale-0.25})`
  340. refView.current.style.transformOrigin = `${50/scale-0.25}px ${50/scale-0.25}px`
  341. setScale(scale-0.25)
  342. }
  343. }
  344. const handleOpenWatch = () => !watch&&setWatch(true)
  345. const handleCloseWatch = (e:any) => {
  346. const id = e.target.id
  347. if (id === 'overlay' || id === 'close') {
  348. setWatch(false)
  349. refView.current.style.transform = 'scale(1)'
  350. setScale(1)
  351. }
  352. }
  353. const handleClose = (type: string | undefined): void => {
  354. if (type === 'copy') copied('Link')
  355. if (type === 'delete') setModal(true)
  356. setAnchorEl(null)
  357. setSelected(false)
  358. }
  359. const handleDeleteModal = (e: any) => {
  360. const id = e.target.id
  361. if (id === 'overlay' || id === 'cancel') return setModal(false)
  362. if (id === 'delete') {
  363. removeMessageById(_id)
  364. setModal(false)
  365. }
  366. }
  367. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  368. e.preventDefault()
  369. setAnchorEl(e.currentTarget)
  370. setSelected(true)
  371. }
  372. const handleEmojiMenu = ({ target }: any): void => {
  373. const idEmoji = target.id
  374. if (idEmoji === emoji) {updateMessageById(_id,'')
  375. } else updateMessageById(_id,idEmoji)
  376. }
  377. return (watch ?
  378. <div onClick={handleCloseWatch} id='overlay' className={classes.overlay}>
  379. <div className={classes.topBar}>
  380. <div className={classes.wrapperCredentials}>
  381. <ListItemIcon >
  382. <Avatar alt={name} src={url?url:undefined}
  383. sx={{ background: color, width: 44, height: 44 }}>
  384. {!url&&`${firstLetter(name)}${firstLetter(lastName)}`}
  385. </Avatar>
  386. </ListItemIcon>
  387. <ListItemText primary={`${firstLetter(name)}${slicedWord(name, 15, 1)}
  388. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  389. primaryTypographyProps={{ color: '#ffffff' }}
  390. secondary={timeStampEU(createdAt)} secondaryTypographyProps={{ color: '#ffffff' }} />
  391. </div>
  392. <div className={classes.wrapperIcons}>
  393. <ZoomOutIcon onClick={handleDecreaseScale}
  394. className={classes.magnifying} fontSize='large' />
  395. <ZoomInIcon onClick={handleIncreaseScale}
  396. className={classes.magnifying} fontSize='large' />
  397. <DownloadForOfflineIcon onClick={() => handleDownload(url, fullType)}
  398. className={classes.downloadIcon} fontSize='large' />
  399. <CloseIcon id='close' onClick={handleCloseWatch}
  400. className={classes.iconCloseOverlay} fontSize='large' />
  401. </div>
  402. </div>
  403. <div ref={refView} className={classes.wrapperImage}>
  404. <img className={classes.innerImage}
  405. width='100%' height='auto' alt='imageItem' src={url} />
  406. </div>
  407. </div> :
  408. <div className={classes.container} style={{marginBottom:tongue?12:0}}>
  409. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  410. style={{backgroundColor:selected?'#ced8d7':'#deffa9',pointerEvents:isSomeSelected?'none':'auto'}}>
  411. <Typography style={{color: "#26afee"}} variant="h6" align="right">
  412. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  413. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  414. </Typography>
  415. <div className={classes.wrapperInner}>
  416. <ImageIcon onClick={() => handleDownload(url, fullType)}
  417. className={classes.folderIcon} fontSize='large' />
  418. <img onClick={handleOpenWatch} className={classes.image} alt='message pic' src={url}
  419. style={{ backgroundColor: url ? '' : color }} width='300' height='400' />
  420. </div>
  421. <ListItemText style={{wordBreak:'break-word'}} secondary={caption} secondaryTypographyProps={{color: "#000000"}}/>
  422. <div className={classes.informationWrapper}>
  423. <div className={classes.time} style={{ color: '#18bd03'}}>{`${edited?'edited ':''}${timeStampMessage(createdAt)}`}</div>
  424. {watched ? <DoneAllIcon style={{ color: '#18bd03', marginLeft: 5 }} fontSize='small' /> :
  425. <DoneIcon style={{ color: '#18bd03',marginLeft:5}} fontSize='small' />}
  426. </div>
  427. {tongue&&<div className={classes.avatarIcon}>
  428. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  429. sx={{ background: color, width: 40, height: 40 }}>
  430. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  431. </Avatar>
  432. </div>}
  433. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  434. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#ced8d7':'#deffa9'}`}}></span>}
  435. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  436. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  437. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  438. onClick={() => handleSelected(_id)}/></div>}
  439. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  440. anchorEl={anchorEl} open={open} onClose={handleClose}>
  441. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  442. {emojisArr.map((el:string, i:number) =>
  443. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  444. </MenuItem>
  445. <Divider />
  446. <MenuItem onClick={() => {
  447. handleReply(_id)
  448. handleClose(undefined)
  449. }}>
  450. <ReplyIcon />
  451. Reply
  452. </MenuItem>
  453. <MenuItem onClick={() => {
  454. handleForward(_id)
  455. handleClose(undefined)
  456. }}>
  457. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  458. Forward
  459. </MenuItem>
  460. <MenuItem onClick={() => {
  461. handleEdit(_id)
  462. handleClose(undefined)
  463. }}>
  464. <EditIcon/>
  465. Edit
  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 MessageRightImage