index.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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 Divider from '@mui/material/Divider';
  13. import { CopyToClipboard } from 'react-copy-to-clipboard';
  14. import { removeMessageById,updateMessageById } from "../../../../../../api-data";
  15. import { timeStampMessage,handleDownload,copied,emojisArr } from '../../../../../../helpers'
  16. const { Player } = require('video-react')
  17. const StyledMenu = styled((props:any) => (
  18. <Menu
  19. elevation={0}
  20. anchorOrigin={{
  21. vertical: 'top',
  22. horizontal: 'right',
  23. }}
  24. transformOrigin={{
  25. vertical: 'bottom',
  26. horizontal: 'right',
  27. }}
  28. {...props}
  29. />
  30. ))(({ theme }:any) => ({
  31. '& .MuiPaper-root': {
  32. borderRadius: 10,
  33. marginTop: theme.spacing(0),
  34. minWidth: 220,
  35. color:
  36. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  37. boxShadow:
  38. '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',
  39. '& .MuiMenu-list': {
  40. padding: '4px 4px',
  41. },
  42. '& .MuiMenuItem-root': {
  43. marginBottom: theme.spacing(1),
  44. '& .MuiSvgIcon-root': {
  45. fontSize: 21,
  46. color: theme.palette.text.secondary,
  47. marginRight: theme.spacing(2),
  48. }
  49. },
  50. },
  51. }));
  52. const useStyles = makeStyles({
  53. container: {
  54. display: "flex",
  55. justifyContent: "flex-start",
  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. captionWrapper: {
  145. position: "absolute",
  146. fontSize: ".85em",
  147. color: '#414141',
  148. maxWidth:'76%',
  149. fontWeight:600,
  150. bottom: -25,
  151. left: 12,
  152. borderRadius: 5,
  153. wordBreak:'break-word',
  154. textAlign: "left",
  155. font: "400 .9em 'Open Sans', sans-serif",
  156. backgroundColor: '#deffa9',
  157. padding:10,
  158. "&:after": {
  159. content: "''",
  160. position: "absolute",
  161. width: "0",
  162. height: "0",
  163. borderBottom: "15px solid #deffa9",
  164. borderLeft: "15px solid transparent",
  165. borderRight: "15px solid transparent",
  166. bottom: '0px',
  167. left: "-15px"
  168. },
  169. "&:before": {
  170. content: "''",
  171. position: "absolute",
  172. width: "0",
  173. height: "0",
  174. borderBottom: "17px solid #deffa9",
  175. borderLeft: "16px solid transparent",
  176. borderRight: "16px solid transparent",
  177. bottom: "-1px",
  178. left: "-17px"
  179. }
  180. },
  181. player: {
  182. backgroundColor: '#ffffff',
  183. },
  184. playerActive: {
  185. backgroundColor: '#babdbc',
  186. },
  187. modalDelete: {
  188. background: '#ffffff',
  189. position: 'absolute',
  190. content:'',
  191. width: '20%',
  192. height:'auto',
  193. left: '40%',
  194. bottom: '48.5%',
  195. borderRadius: 10,
  196. padding: 10,
  197. display: 'flex',
  198. flexDirection:'column'
  199. },
  200. overlay: {
  201. position: 'fixed',
  202. top: 0,
  203. left: 0,
  204. width: '100vw',
  205. height: '100vh',
  206. zIndex: 100,
  207. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  208. overflowY: 'hidden',
  209. },
  210. emojiTitle: {
  211. position: "absolute",
  212. fontSize: "1.7em",
  213. fontWeight:600,
  214. bottom: 0,
  215. right: -40,
  216. },
  217. emojiCompanionTitle: {
  218. position: "absolute",
  219. fontSize: "1.7em",
  220. fontWeight:600,
  221. bottom: '2rem',
  222. right: -40,
  223. },
  224. emoji: {
  225. cursor: 'pointer',
  226. fontSize: '1.7rem',
  227. transition: 'all 0.3s',
  228. '&:hover': {
  229. transform: 'scale(1.5)'
  230. }
  231. },
  232. emojiActive: {
  233. cursor: 'pointer',
  234. fontSize: '1.2rem',
  235. animation: `$emoji 0.6s ease-out`,
  236. animationDirection: 'forwards',
  237. animationIterationCount: 1,
  238. },
  239. '@keyframes emoji': {
  240. '5%': { transform: 'translateY(1rem)'},
  241. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  242. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  243. '80%': {opacity: 0},
  244. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  245. },
  246. });
  247. interface IMessageLeftVideo {
  248. url:string,
  249. createdAt: string,
  250. fullType: string,
  251. caption: string,
  252. emoji: string,
  253. emojiCompanion: string,
  254. _id:string
  255. }
  256. const MessageLeftVideo = ({ url,createdAt,fullType,caption,emoji,emojiCompanion,_id }:IMessageLeftVideo) => {
  257. const classes = useStyles();
  258. const [anchorEl, setAnchorEl] = useState<any>(null);
  259. const [selected, setSelected] = useState<boolean>(false);
  260. const [modal,setModal] = useState<boolean>(false)
  261. const open = Boolean(anchorEl);
  262. const handleClose = (type: string | undefined): void => {
  263. if (type === 'copy') copied('Link')
  264. if (type === 'delete') setModal(true)
  265. setAnchorEl(null)
  266. setSelected(false)
  267. }
  268. const handleDeleteModal = (e: any) => {
  269. const id = e.target.id
  270. if (id === 'overlay' || id === 'cancel') return setModal(false)
  271. if (id === 'delete') {
  272. removeMessageById(_id)
  273. setModal(false)
  274. }
  275. }
  276. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  277. e.preventDefault()
  278. setAnchorEl(e.currentTarget)
  279. setSelected(true)
  280. }
  281. const handleEmojiMenu = ({ target }: any): void => {
  282. const idEmoji = target.id
  283. if (idEmoji === emoji) {updateMessageById(_id,'')
  284. } else updateMessageById(_id,idEmoji)
  285. }
  286. return (
  287. <div className={classes.container} style={{marginBottom:caption?40:15}}>
  288. <div onContextMenu={(e) => handleContextMenu(e)}
  289. className={selected? classes.wrapperActive:classes.wrapper}>
  290. <VideoFileIcon fontSize='large' style={{ color:'#03b003'}}/>
  291. <Player className={selected?classes.playerActive:classes.player} playsInline src={url}/>
  292. <IconButton onClick={() => handleDownload(url, fullType)} className={classes.bntDownload} >
  293. <FileDownloadIcon fontSize='medium'/>
  294. </IconButton>
  295. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  296. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  297. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  298. {caption&&<div className={classes.captionWrapper}>{caption}</div>}
  299. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  300. anchorEl={anchorEl} open={open} onClose={handleClose}>
  301. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  302. {emojisArr.map((el:string, i:number) =>
  303. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  304. </MenuItem>
  305. <Divider/>
  306. <CopyToClipboard onCopy={() => handleClose('copy')} text={url}>
  307. <MenuItem>
  308. <ContentCopyIcon />
  309. Copy Video link
  310. </MenuItem>
  311. </CopyToClipboard>
  312. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  313. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  314. Delete message
  315. </MenuItem>
  316. </StyledMenu>
  317. {modal &&
  318. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  319. <div className={classes.modalDelete}>
  320. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  321. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  322. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  323. DELETE MESSAGE
  324. </Button>
  325. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  326. CANCEL
  327. </Button>
  328. </div>
  329. </div>}
  330. </div>
  331. </div>
  332. )};
  333. export default MessageLeftVideo