index.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import { makeStyles } from '@material-ui/core'
  2. import { useState } from 'react';
  3. import ImageListItem from '@mui/material/ImageListItem';
  4. import DownloadForOfflineIcon from '@mui/icons-material/DownloadForOffline';
  5. import { handleDownload,timeStampEU,prodBaseURL } from '../../../../../../helpers'
  6. const useStyles = makeStyles({
  7. overlay: {
  8. position: 'fixed',
  9. top: 0,
  10. left: 0,
  11. width: '100vw',
  12. height: '100vh',
  13. zIndex: 100,
  14. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  15. overflowY: 'hidden',
  16. boxSizing: 'border-box',
  17. display: 'flex',
  18. justifyContent: 'center',
  19. alignContent: 'center',
  20. alignItems: 'center'
  21. },
  22. wrapper: {
  23. width: '30%',
  24. maxHeight: '80%',
  25. position: 'relative',
  26. display: 'flex',
  27. },
  28. downloadIcon: {
  29. position: 'absolute',
  30. content: '',
  31. right: 0,
  32. top: -40,
  33. cursor: 'pointer',
  34. color: '#e9e7e7',
  35. padding: 0,
  36. borderRadius: '50%',
  37. '&:hover': {
  38. backgroundColor: '#ffffff',
  39. color: '#b8b7b7',
  40. }
  41. },
  42. img: {
  43. cursor:'pointer',
  44. '&:hover': {
  45. scale:0.98
  46. }
  47. },
  48. time: {
  49. position: 'absolute',
  50. content: '',
  51. color: '#ffffff',
  52. top: -30,
  53. left: 0,
  54. borderRadius: 10,
  55. padding:'2px 6px 2px 6px',
  56. backgroundColor:'#707070'
  57. }
  58. });
  59. const MediaListItem = ({ message,fullType,updatedAt }: { message: string,fullType:string,updatedAt:string }) => {
  60. const classes = useStyles();
  61. const [watch, setWatch] = useState<boolean>(false)
  62. const handleOpenWatch = () => !watch && setWatch(true)
  63. const handleCloseWatch = (e:any) => e.target.id === 'overlay'&&watch&&setWatch(false)
  64. const url = `${prodBaseURL}/${message}`
  65. return (watch ?
  66. <div onClick={handleCloseWatch} id='overlay' className={classes.overlay}>
  67. <div className={classes.wrapper}>
  68. <span className={classes.time}>{timeStampEU(updatedAt)}</span>
  69. <DownloadForOfflineIcon className={classes.downloadIcon} fontSize='large'
  70. onClick={() => handleDownload(url, fullType)}/>
  71. <img width='100%' height='auto' alt='imageItem' src={url} />
  72. </div>
  73. </div> :
  74. <ImageListItem>
  75. <img onClick={handleOpenWatch} className={classes.img}
  76. src={`${url}?w=164&h=164&fit=crop&auto=format`}
  77. srcSet={`${url}?w=164&h=164&fit=crop&auto=format&dpr=2 2x`}
  78. alt='imageItem' loading="lazy" />
  79. </ImageListItem>
  80. )
  81. }
  82. export default MediaListItem