index.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. import { makeStyles } from "@material-ui/core/styles";
  2. import { styled } from '@mui/material/styles';
  3. import { useState } from "react";
  4. import { IconButton } from "@material-ui/core";
  5. import VideoFileIcon from '@mui/icons-material/VideoFile';
  6. import FileDownloadIcon from '@mui/icons-material/FileDownload';
  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 { CopyToClipboard } from 'react-copy-to-clipboard';
  13. import { removeMessageById } from "../../../../../../api-data";
  14. import { timeStampMessage,handleDownload,copied } from '../../../../../../helpers'
  15. const { Player } = require('video-react')
  16. const StyledMenu = styled((props:any) => (
  17. <Menu
  18. elevation={0}
  19. anchorOrigin={{
  20. vertical: 'top',
  21. horizontal: 'right',
  22. }}
  23. transformOrigin={{
  24. vertical: 'bottom',
  25. horizontal: 'right',
  26. }}
  27. {...props}
  28. />
  29. ))(({ theme }:any) => ({
  30. '& .MuiPaper-root': {
  31. borderRadius: 10,
  32. marginTop: theme.spacing(0),
  33. minWidth: 220,
  34. color:
  35. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  36. boxShadow:
  37. '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',
  38. '& .MuiMenu-list': {
  39. padding: '4px 4px',
  40. },
  41. '& .MuiMenuItem-root': {
  42. marginBottom: theme.spacing(1),
  43. '& .MuiSvgIcon-root': {
  44. fontSize: 21,
  45. color: theme.palette.text.secondary,
  46. marginRight: theme.spacing(2),
  47. }
  48. },
  49. },
  50. }));
  51. const useStyles = makeStyles({
  52. container: {
  53. display: "flex",
  54. justifyContent: "flex-start",
  55. marginBottom:15
  56. },
  57. wrapper: {
  58. position: 'relative',
  59. display: 'flex',
  60. justifyContent: 'space-between',
  61. alignContent: 'center',
  62. alignItems: 'center',
  63. width: 400,
  64. padding: '12px 5px 18px 5px',
  65. backgroundColor: '#ffffff',
  66. borderRadius: 7,
  67. "&:after": {
  68. content: "''",
  69. position: "absolute",
  70. width: "0",
  71. height: "0",
  72. borderBottom: "15px solid #ffffff",
  73. borderLeft: "15px solid transparent",
  74. borderRight: "15px solid transparent",
  75. bottom: '0px',
  76. left: "-15px"
  77. },
  78. "&:before": {
  79. content: "''",
  80. position: "absolute",
  81. width: "0",
  82. height: "0",
  83. borderBottom: "17px solid #ffffff",
  84. borderLeft: "16px solid transparent",
  85. borderRight: "16px solid transparent",
  86. bottom: "0px",
  87. left: "-17px"
  88. }
  89. },
  90. wrapperActive: {
  91. position: 'relative',
  92. display: 'flex',
  93. justifyContent: 'space-between',
  94. alignContent: 'center',
  95. alignItems: 'center',
  96. width: 400,
  97. padding: '12px 5px 18px 5px',
  98. backgroundColor: '#babdbc',
  99. borderRadius: 7,
  100. "&:after": {
  101. content: "''",
  102. position: "absolute",
  103. width: "0",
  104. height: "0",
  105. borderBottom: "15px solid #babdbc",
  106. borderLeft: "15px solid transparent",
  107. borderRight: "15px solid transparent",
  108. bottom: '0px',
  109. left: "-15px"
  110. },
  111. "&:before": {
  112. content: "''",
  113. position: "absolute",
  114. width: "0",
  115. height: "0",
  116. borderBottom: "17px solid #babdbc",
  117. borderLeft: "16px solid transparent",
  118. borderRight: "16px solid transparent",
  119. bottom: "0px",
  120. left: "-17px"
  121. }
  122. },
  123. bntDownload: {
  124. backgroundColor: 'inherit',
  125. color: '#54b0fc',
  126. width: 30,
  127. height: 30,
  128. marginLeft:5,
  129. '&:hover': {
  130. backgroundColor: '#54b0fc',
  131. color:'#ffffff'
  132. }
  133. },
  134. time: {
  135. position: "absolute",
  136. fontSize: ".65em",
  137. fontWeight:600,
  138. bottom: 0,
  139. right: 6,
  140. color: '#414141',
  141. padding: 3,
  142. borderRadius: 5,
  143. },
  144. caption: {
  145. position: "absolute",
  146. fontSize: ".65em",
  147. fontWeight:600,
  148. bottom: 0,
  149. left: 6,
  150. color: '#000000',
  151. padding: 3,
  152. borderRadius: 5,
  153. },
  154. player: {
  155. backgroundColor: '#ffffff',
  156. },
  157. playerActive: {
  158. backgroundColor: '#babdbc',
  159. },
  160. modalDelete: {
  161. background: '#ffffff',
  162. position: 'absolute',
  163. content:'',
  164. width: '20%',
  165. height:'auto',
  166. left: '40%',
  167. bottom: '48.5%',
  168. borderRadius: 10,
  169. padding: 10,
  170. display: 'flex',
  171. flexDirection:'column'
  172. },
  173. overlay: {
  174. position: 'fixed',
  175. top: 0,
  176. left: 0,
  177. width: '100vw',
  178. height: '100vh',
  179. zIndex: 100,
  180. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  181. overflowY: 'hidden',
  182. },
  183. });
  184. interface IMessageLeftVideo {
  185. url:string,
  186. createdAt: string,
  187. fullType: string,
  188. caption :string,
  189. _id:string
  190. }
  191. const MessageLeftVideo = ({ url,createdAt,fullType,caption,_id }:IMessageLeftVideo) => {
  192. const classes = useStyles();
  193. const [anchorEl, setAnchorEl] = useState<any>(null);
  194. const [selected, setSelected] = useState<boolean>(false);
  195. const [modal,setModal] = useState<boolean>(false)
  196. const open = Boolean(anchorEl);
  197. const handleClose = (type: string | undefined): void => {
  198. if (type === 'copy') copied('Link')
  199. if (type === 'delete') setModal(true)
  200. setAnchorEl(null)
  201. setSelected(false)
  202. }
  203. const handleDeleteModal = (e: any) => {
  204. const id = e.target.id
  205. if (id === 'overlay' || id === 'cancel') return setModal(false)
  206. if (id === 'delete') {
  207. removeMessageById(_id)
  208. setModal(false)
  209. }
  210. }
  211. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  212. e.preventDefault()
  213. setAnchorEl(e.currentTarget)
  214. setSelected(true)
  215. }
  216. return (
  217. <div className={classes.container}>
  218. <div onContextMenu={(e) => handleContextMenu(e)}
  219. className={selected? classes.wrapperActive:classes.wrapper}>
  220. <VideoFileIcon fontSize='large' style={{ color:'#03b003'}}/>
  221. <Player className={selected?classes.playerActive:classes.player} playsInline src={url}/>
  222. <IconButton onClick={() => handleDownload(url, fullType)} className={classes.bntDownload} >
  223. <FileDownloadIcon fontSize='medium'/>
  224. </IconButton>
  225. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  226. <div className={classes.caption}>{caption}</div>
  227. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  228. anchorEl={anchorEl} open={open} onClose={handleClose}>
  229. <CopyToClipboard onCopy={() => handleClose('copy')} text={url}>
  230. <MenuItem>
  231. <ContentCopyIcon />
  232. Copy Video link
  233. </MenuItem>
  234. </CopyToClipboard>
  235. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  236. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  237. Delete message
  238. </MenuItem>
  239. </StyledMenu>
  240. {modal &&
  241. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  242. <div className={classes.modalDelete}>
  243. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  244. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  245. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  246. DELETE MESSAGE
  247. </Button>
  248. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  249. CANCEL
  250. </Button>
  251. </div>
  252. </div>}
  253. </div>
  254. </div>
  255. )};
  256. export default MessageLeftVideo