index.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { Carousel } from 'react-responsive-carousel';
  3. import { IconButton } from "@material-ui/core";
  4. import ImageIcon from '@mui/icons-material/Image';
  5. import FileDownloadIcon from '@mui/icons-material/FileDownload';
  6. import { useState } from "react";
  7. import { timeStampMessage, timeStampFilter } from '../../../../../../helpers'
  8. const useStyles = makeStyles({
  9. container: {
  10. display: "flex",
  11. justifyContent: "flex-start",
  12. width:'auto',
  13. maxWidth: '80%',
  14. marginBottom:15
  15. },
  16. wrapper: {
  17. width: 400,
  18. position: 'relative',
  19. display: 'flex',
  20. alignItems: 'center',
  21. alignContent: 'center',
  22. justifyContent: 'space-between',
  23. borderRadius: 7,
  24. padding: '12px 5px 12px 5px',
  25. backgroundColor: '#ffffff',
  26. "&:after": {
  27. content: "''",
  28. position: "absolute",
  29. width: "0",
  30. height: "0",
  31. borderBottom: "15px solid #ffffff",
  32. borderLeft: "15px solid transparent",
  33. borderRight: "15px solid transparent",
  34. bottom: "0",
  35. right: "-15px"
  36. },
  37. "&:before": {
  38. content: "''",
  39. position: "absolute",
  40. width: "0",
  41. height: "0",
  42. borderBottom: "17px solid #ffffff",
  43. borderLeft: "16px solid transparent",
  44. borderRight: "16px solid transparent",
  45. bottom: "0px",
  46. right: "-17px"
  47. }
  48. },
  49. image: {
  50. borderRadius: 7,
  51. width: 300,
  52. maxHeight: 400,
  53. cursor: 'pointer',
  54. },
  55. time: {
  56. position: "absolute",
  57. fontSize: ".65em",
  58. fontWeight:600,
  59. bottom: 0,
  60. right: 6,
  61. color: '#414141',
  62. padding: 3,
  63. borderRadius: 5,
  64. zIndex:10
  65. },
  66. bntDownload: {
  67. backgroundColor: '#ffffff',
  68. color: '#54b0fc',
  69. width: 30,
  70. height:30,
  71. '&:hover': {
  72. backgroundColor: '#54b0fc',
  73. color:'#ffffff'
  74. }
  75. },
  76. overlay: {
  77. position: 'fixed',
  78. top: 0,
  79. left: 0,
  80. width: '100vw',
  81. height: '100vh',
  82. zIndex: 100,
  83. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  84. border: 'solid 1px rgba(179, 179, 179, 0.6)',
  85. overflowY: 'hidden',
  86. boxSizing: 'border-box',
  87. display: 'flex',
  88. justifyContent: 'center',
  89. alignContent: 'center',
  90. alignItems: 'center'
  91. },
  92. carousel: {
  93. width:'40%'
  94. }
  95. });
  96. interface IMessagesLeftImage {
  97. url:string,
  98. updatedAt:string,
  99. color: string,
  100. message: string,
  101. messages: any
  102. }
  103. const MessagesLeftImage = ({url,updatedAt,color,message,messages}:IMessagesLeftImage) => {
  104. const classes = useStyles();
  105. const [watch, setWatch] = useState<boolean>(false)
  106. const handleOpenWatch = () => !watch&&setWatch(true)
  107. const handleCloseWatch = (e:any) => {
  108. if (e.target.id === 'overlay' && watch) setWatch(false)
  109. }
  110. return (watch ?
  111. <div onClick={handleCloseWatch} id='overlay' className={classes.overlay}>
  112. <Carousel className={classes.carousel}>
  113. {[...messages].reduce((acc, el) => {
  114. if (el.type === 'image' && el.message !== message) {
  115. acc.push(el)
  116. return acc
  117. } else if (el.type === 'image') {
  118. acc.unshift(el)
  119. return acc
  120. }
  121. return acc
  122. },[]).map((el:any) => <div>
  123. <img alt='pic' src={`http://localhost:3000/${el.message}`}/>
  124. <p className="legend">{timeStampFilter(el.updatedAt)}</p>
  125. </div>)}
  126. </Carousel>
  127. </div> :
  128. <div className={classes.container}>
  129. <div className={classes.wrapper}>
  130. <ImageIcon fontSize='large' style={{ color: '#bd9a00' }} />
  131. <img onClick={handleOpenWatch} className={classes.image} alt='message pic' src={url}
  132. style={{ backgroundColor: url ? '' : color }} width='300' height='400' />
  133. <a href={url} target="_blank" rel="noreferrer" download>
  134. <IconButton className={classes.bntDownload} >
  135. <FileDownloadIcon fontSize='medium'/>
  136. </IconButton>
  137. </a>
  138. <div className={classes.time}>{timeStampMessage(updatedAt)}</div>
  139. </div>
  140. </div>
  141. )};
  142. export default MessagesLeftImage