index.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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-end",
  56. marginBottom:15
  57. },
  58. wrapper: {
  59. position: 'relative',
  60. display: 'flex',
  61. justifyContent: 'space-between',
  62. alignContent: 'center',
  63. alignItems: 'center',
  64. width: 400,
  65. padding: '12px 5px 18px 5px',
  66. backgroundColor: '#deffa9',
  67. borderRadius: 7,
  68. "&:after": {
  69. content: "''",
  70. position: "absolute",
  71. width: "0",
  72. height: "0",
  73. borderBottom: "15px solid #deffa9",
  74. borderLeft: "15px solid transparent",
  75. borderRight: "15px solid transparent",
  76. bottom: "0",
  77. right: "-15px"
  78. },
  79. "&:before": {
  80. content: "''",
  81. position: "absolute",
  82. width: "0",
  83. height: "0",
  84. borderBottom: "17px solid #deffa9",
  85. borderLeft: "16px solid transparent",
  86. borderRight: "16px solid transparent",
  87. bottom: "0px",
  88. right: "-17px"
  89. }
  90. },
  91. wrapperActive: {
  92. position: 'relative',
  93. display: 'flex',
  94. justifyContent: 'space-between',
  95. alignContent: 'center',
  96. alignItems: 'center',
  97. width: 400,
  98. padding: '12px 5px 18px 5px',
  99. backgroundColor: '#ced8d7',
  100. borderRadius: 7,
  101. "&:after": {
  102. content: "''",
  103. position: "absolute",
  104. width: "0",
  105. height: "0",
  106. borderBottom: "15px solid #ced8d7",
  107. borderLeft: "15px solid transparent",
  108. borderRight: "15px solid transparent",
  109. bottom: "0",
  110. right: "-15px"
  111. },
  112. "&:before": {
  113. content: "''",
  114. position: "absolute",
  115. width: "0",
  116. height: "0",
  117. borderBottom: "17px solid #ced8d7",
  118. borderLeft: "16px solid transparent",
  119. borderRight: "16px solid transparent",
  120. bottom: "0px",
  121. right: "-17px"
  122. }
  123. },
  124. bntDownload: {
  125. backgroundColor: 'inherit',
  126. color: '#54b0fc',
  127. width: 30,
  128. height: 30,
  129. marginLeft:5,
  130. '&:hover': {
  131. backgroundColor: '#54b0fc',
  132. color:'#ffffff'
  133. }
  134. },
  135. time: {
  136. position: "absolute",
  137. fontSize: ".65em",
  138. fontWeight:600,
  139. bottom: 0,
  140. right: 6,
  141. color: '#414141',
  142. padding: 3,
  143. borderRadius: 5,
  144. },
  145. caption: {
  146. position: "absolute",
  147. fontSize: ".65em",
  148. fontWeight:600,
  149. bottom: 1,
  150. left: 6,
  151. color: '#000000',
  152. padding: 3,
  153. borderRadius: 5,
  154. },
  155. player: {
  156. backgroundColor: '#deffa9',
  157. },
  158. playerActive: {
  159. backgroundColor: '#ced8d7',
  160. },
  161. modalDelete: {
  162. background: '#ffffff',
  163. position: 'absolute',
  164. content:'',
  165. width: '20%',
  166. height:'auto',
  167. left: '40%',
  168. bottom: '48.5%',
  169. borderRadius: 10,
  170. padding: 10,
  171. display: 'flex',
  172. flexDirection:'column'
  173. },
  174. overlay: {
  175. position: 'fixed',
  176. top: 0,
  177. left: 0,
  178. width: '100vw',
  179. height: '100vh',
  180. zIndex: 100,
  181. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  182. overflowY: 'hidden',
  183. },
  184. emojiTitle: {
  185. position: "absolute",
  186. fontSize: "1.7em",
  187. fontWeight:600,
  188. bottom: 0,
  189. left: -40,
  190. },
  191. emojiCompanionTitle: {
  192. position: "absolute",
  193. fontSize: "1.7em",
  194. fontWeight:600,
  195. bottom: '2rem',
  196. left: -40,
  197. },
  198. emoji: {
  199. cursor: 'pointer',
  200. fontSize: '1.7rem',
  201. transition: 'all 0.3s',
  202. '&:hover': {
  203. transform: 'scale(1.5)'
  204. }
  205. },
  206. emojiActive: {
  207. cursor: 'pointer',
  208. fontSize: '1.2rem',
  209. animation: `$emoji 0.6s ease-out`,
  210. animationDirection: 'forwards',
  211. animationIterationCount: 1,
  212. },
  213. '@keyframes emoji': {
  214. '5%': { transform: 'translateY(1rem)'},
  215. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  216. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  217. '80%': {opacity: 0},
  218. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  219. },
  220. });
  221. interface IMessageRightVideo {
  222. url:string,
  223. createdAt: string,
  224. fullType: string,
  225. caption: string,
  226. emoji: string,
  227. emojiCompanion: string,
  228. _id:string
  229. }
  230. const MessageRightVideo = ({ url,createdAt,fullType,caption,emoji,emojiCompanion,_id }:IMessageRightVideo) => {
  231. const classes = useStyles();
  232. const [anchorEl, setAnchorEl] = useState<any>(null);
  233. const [selected, setSelected] = useState<boolean>(false);
  234. const [emojiIndex, setEmojiIndex] = useState<string | null>(null);
  235. const [modal,setModal] = useState<boolean>(false)
  236. const open = Boolean(anchorEl);
  237. const handleClose = (type: string | undefined): void => {
  238. if (type === 'copy') copied('Link')
  239. if (type === 'delete') setModal(true)
  240. setAnchorEl(null)
  241. setSelected(false)
  242. }
  243. const handleDeleteModal = (e: any) => {
  244. const id = e.target.id
  245. if (id === 'overlay' || id === 'cancel') return setModal(false)
  246. if (id === 'delete') {
  247. removeMessageById(_id)
  248. setModal(false)
  249. }
  250. }
  251. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  252. e.preventDefault()
  253. setAnchorEl(e.currentTarget)
  254. setSelected(true)
  255. }
  256. const handleEmojiMenu = ({ target }: any): void => {
  257. const idEmoji = target.id
  258. if (idEmoji === emoji) {
  259. updateMessageById(_id,'')
  260. setEmojiIndex(null)
  261. } else {
  262. updateMessageById(_id,idEmoji)
  263. setEmojiIndex(idEmoji)
  264. }
  265. }
  266. return (
  267. <div className={classes.container}>
  268. <div onContextMenu={(e) => handleContextMenu(e)}
  269. className={selected? classes.wrapperActive:classes.wrapper}>
  270. <VideoFileIcon fontSize='large' style={{ color:'#03b003'}}/>
  271. <Player className={selected?classes.playerActive:classes.player} playsInline src={url}/>
  272. <IconButton onClick={() => handleDownload(url, fullType)} className={classes.bntDownload}>
  273. <FileDownloadIcon fontSize='medium'/>
  274. </IconButton>
  275. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  276. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  277. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  278. <div className={classes.caption}>{caption}</div>
  279. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  280. anchorEl={anchorEl} open={open} onClose={handleClose}>
  281. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  282. {emojisArr.map((el:string, i:number) =>
  283. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  284. </MenuItem>
  285. <Divider/>
  286. <CopyToClipboard onCopy={() => handleClose('copy')} text={url}>
  287. <MenuItem>
  288. <ContentCopyIcon />
  289. Copy Video link
  290. </MenuItem>
  291. </CopyToClipboard>
  292. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  293. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  294. Delete message
  295. </MenuItem>
  296. </StyledMenu>
  297. {modal &&
  298. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  299. <div className={classes.modalDelete}>
  300. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  301. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  302. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  303. DELETE MESSAGE
  304. </Button>
  305. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  306. CANCEL
  307. </Button>
  308. </div>
  309. </div>}
  310. </div>
  311. </div>
  312. )};
  313. export default MessageRightVideo