index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 CheckBoxIcon from '@mui/icons-material/CheckBox';
  14. import Checkbox from '@mui/material/Checkbox';
  15. import PushPinIcon from '@mui/icons-material/PushPin';
  16. import CloseIcon from '@mui/icons-material/Close';
  17. import ReplyIcon from '@mui/icons-material/Reply';
  18. import { CopyToClipboard } from 'react-copy-to-clipboard';
  19. import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  20. import { timeStampMessage,handleDownload,copied,emojisArr,slicedWord } from '../../../../../../helpers'
  21. const { Player } = require('video-react')
  22. const StyledMenu = styled((props:any) => (
  23. <Menu
  24. elevation={0}
  25. anchorOrigin={{
  26. vertical: 'top',
  27. horizontal: 'right',
  28. }}
  29. transformOrigin={{
  30. vertical: 'bottom',
  31. horizontal: 'right',
  32. }}
  33. {...props}
  34. />
  35. ))(({ theme }:any) => ({
  36. '& .MuiPaper-root': {
  37. borderRadius: 10,
  38. marginTop: theme.spacing(0),
  39. minWidth: 220,
  40. color:
  41. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  42. boxShadow:
  43. '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',
  44. '& .MuiMenu-list': {
  45. padding: '4px 4px',
  46. },
  47. '& .MuiMenuItem-root': {
  48. marginBottom: theme.spacing(1),
  49. '& .MuiSvgIcon-root': {
  50. fontSize: 21,
  51. color: theme.palette.text.secondary,
  52. marginRight: theme.spacing(2),
  53. }
  54. },
  55. },
  56. }));
  57. const useStyles = makeStyles({
  58. container: {
  59. display: "flex",
  60. justifyContent: "flex-end",
  61. borderRadius: 7,
  62. },
  63. wrapper: {
  64. position: 'relative',
  65. display: 'flex',
  66. justifyContent: 'space-between',
  67. alignContent: 'center',
  68. alignItems: 'center',
  69. width: 400,
  70. padding: '12px 5px 18px 5px',
  71. backgroundColor: '#deffa9',
  72. borderRadius: 7,
  73. "&:after": {
  74. content: "''",
  75. position: "absolute",
  76. width: "0",
  77. height: "0",
  78. borderBottom: "15px solid #deffa9",
  79. borderLeft: "15px solid transparent",
  80. borderRight: "15px solid transparent",
  81. bottom: "0",
  82. right: "-15px"
  83. },
  84. "&:before": {
  85. content: "''",
  86. position: "absolute",
  87. width: "0",
  88. height: "0",
  89. borderBottom: "17px solid #deffa9",
  90. borderLeft: "16px solid transparent",
  91. borderRight: "16px solid transparent",
  92. bottom: "0px",
  93. right: "-17px"
  94. }
  95. },
  96. wrapperActive: {
  97. position: 'relative',
  98. display: 'flex',
  99. justifyContent: 'space-between',
  100. alignContent: 'center',
  101. alignItems: 'center',
  102. width: 400,
  103. padding: '12px 5px 18px 5px',
  104. backgroundColor: '#ced8d7',
  105. borderRadius: 7,
  106. "&:after": {
  107. content: "''",
  108. position: "absolute",
  109. width: "0",
  110. height: "0",
  111. borderBottom: "15px solid #ced8d7",
  112. borderLeft: "15px solid transparent",
  113. borderRight: "15px solid transparent",
  114. bottom: "0",
  115. right: "-15px"
  116. },
  117. "&:before": {
  118. content: "''",
  119. position: "absolute",
  120. width: "0",
  121. height: "0",
  122. borderBottom: "17px solid #ced8d7",
  123. borderLeft: "16px solid transparent",
  124. borderRight: "16px solid transparent",
  125. bottom: "0px",
  126. right: "-17px"
  127. }
  128. },
  129. bntDownload: {
  130. backgroundColor: 'inherit',
  131. color: '#54b0fc',
  132. width: 30,
  133. height: 30,
  134. marginLeft:5,
  135. '&:hover': {
  136. backgroundColor: '#54b0fc',
  137. color:'#ffffff'
  138. }
  139. },
  140. time: {
  141. position: "absolute",
  142. fontSize: ".65em",
  143. fontWeight:600,
  144. bottom: 0,
  145. right: 6,
  146. color: '#414141',
  147. padding: 3,
  148. borderRadius: 5,
  149. },
  150. captionWrapper: {
  151. position: "absolute",
  152. fontSize: ".85em",
  153. color: '#626262',
  154. maxWidth:'76%',
  155. fontWeight:600,
  156. bottom: -25,
  157. right: 40,
  158. borderRadius: 5,
  159. wordBreak:'break-word',
  160. textAlign: "left",
  161. font: "400 .9em 'Open Sans', sans-serif",
  162. backgroundColor: '#ffffff',
  163. padding:10,
  164. "&:after": {
  165. content: "''",
  166. position: "absolute",
  167. width: "0",
  168. height: "0",
  169. borderBottom: "15px solid #ffffff",
  170. borderLeft: "15px solid transparent",
  171. borderRight: "15px solid transparent",
  172. bottom: "0",
  173. right: "-15px"
  174. },
  175. "&:before": {
  176. content: "''",
  177. position: "absolute",
  178. width: "0",
  179. height: "0",
  180. borderBottom: "17px solid #ffffff",
  181. borderLeft: "16px solid transparent",
  182. borderRight: "16px solid transparent",
  183. bottom: "-1px",
  184. right: "-17px"
  185. }
  186. },
  187. player: {
  188. backgroundColor: '#deffa9',
  189. },
  190. playerActive: {
  191. backgroundColor: '#ced8d7',
  192. },
  193. modalDelete: {
  194. background: '#ffffff',
  195. position: 'absolute',
  196. content:'',
  197. width: '20%',
  198. height:'auto',
  199. left: '40%',
  200. bottom: '48.5%',
  201. borderRadius: 10,
  202. padding: 10,
  203. display: 'flex',
  204. flexDirection:'column'
  205. },
  206. overlay: {
  207. position: 'fixed',
  208. top: 0,
  209. left: 0,
  210. width: '100vw',
  211. height: '100vh',
  212. zIndex: 100,
  213. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  214. overflowY: 'hidden',
  215. },
  216. emojiTitle: {
  217. position: "absolute",
  218. fontSize: "1.7em",
  219. fontWeight:600,
  220. bottom: 0,
  221. left: -40,
  222. },
  223. emojiCompanionTitle: {
  224. position: "absolute",
  225. fontSize: "1.7em",
  226. fontWeight:600,
  227. bottom: '2rem',
  228. left: -40,
  229. },
  230. emoji: {
  231. cursor: 'pointer',
  232. fontSize: '1.7rem',
  233. transition: 'all 0.3s',
  234. '&:hover': {
  235. transform: 'scale(1.5)'
  236. }
  237. },
  238. emojiActive: {
  239. cursor: 'pointer',
  240. fontSize: '1.2rem',
  241. animation: `$emoji 0.6s ease-out`,
  242. animationDirection: 'forwards',
  243. animationIterationCount: 1,
  244. },
  245. '@keyframes emoji': {
  246. '5%': { transform: 'translateY(1rem)'},
  247. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  248. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  249. '80%': {opacity: 0},
  250. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  251. },
  252. iconClose: {
  253. '&:hover': {
  254. transform: 'rotate(180deg)',
  255. transition: 'all 250ms ease-out ',
  256. }
  257. },
  258. });
  259. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  260. interface IMessageRightVideo {
  261. url:string,
  262. createdAt: string,
  263. fullType: string,
  264. caption: string,
  265. emoji: string,
  266. emojiCompanion: string,
  267. pinned: boolean,
  268. isSomeSelected: boolean,
  269. isSelected:(_id:string) => boolean,
  270. handleSelected: (_id:string) => void,
  271. _id: string,
  272. nightMode: boolean,
  273. handleReply: (_id: string) => void
  274. }
  275. const MessageRightVideo = ({ url,createdAt,fullType,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply }:IMessageRightVideo) => {
  276. const classes = useStyles();
  277. const [anchorEl, setAnchorEl] = useState<any>(null);
  278. const [selected, setSelected] = useState<boolean>(false);
  279. const [modal,setModal] = useState<boolean>(false)
  280. const open = Boolean(anchorEl);
  281. const checked = isSelected(_id)
  282. const handleClose = (type: string | undefined): void => {
  283. if (type === 'copy') copied('Link')
  284. if (type === 'delete') setModal(true)
  285. setAnchorEl(null)
  286. setSelected(false)
  287. }
  288. const handleDeleteModal = (e: any) => {
  289. const id = e.target.id
  290. if (id === 'overlay' || id === 'cancel') return setModal(false)
  291. if (id === 'delete') {
  292. removeMessageById(_id)
  293. setModal(false)
  294. }
  295. }
  296. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  297. e.preventDefault()
  298. setAnchorEl(e.currentTarget)
  299. setSelected(true)
  300. }
  301. const handleEmojiMenu = ({ target }: any): void => {
  302. const idEmoji = target.id
  303. if (idEmoji === emoji) {updateMessageById(_id,'')
  304. } else updateMessageById(_id,idEmoji)
  305. }
  306. return (
  307. <div className={classes.container} style={{ marginBottom: caption ? 40 : 15}}>
  308. <div onContextMenu={(e) => handleContextMenu(e)}
  309. className={selected ? classes.wrapperActive : classes.wrapper}
  310. style={{pointerEvents:isSomeSelected?'none':'auto'}}>
  311. <VideoFileIcon fontSize='large' style={{ color:'#03b003'}}/>
  312. <Player className={selected?classes.playerActive:classes.player} playsInline src={url}/>
  313. <IconButton onClick={() => handleDownload(url, fullType)} className={classes.bntDownload}>
  314. <FileDownloadIcon fontSize='medium'/>
  315. </IconButton>
  316. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  317. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  318. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  319. {caption&&<div className={classes.captionWrapper}>{slicedWord(caption, 20, 0)}</div>}
  320. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  321. anchorEl={anchorEl} open={open} onClose={handleClose}>
  322. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  323. {emojisArr.map((el:string, i:number) =>
  324. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  325. </MenuItem>
  326. <Divider />
  327. <MenuItem onClick={() => {
  328. handleReply(_id)
  329. handleClose(undefined)
  330. }}>
  331. <ReplyIcon />
  332. Reply
  333. </MenuItem>
  334. <MenuItem>
  335. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  336. Forward
  337. </MenuItem>
  338. <CopyToClipboard onCopy={() => handleClose('copy')} text={url}>
  339. <MenuItem>
  340. <ContentCopyIcon />
  341. Copy Link
  342. </MenuItem>
  343. </CopyToClipboard>
  344. <MenuItem onClick={() => {
  345. pinMessageById(_id, !pinned)
  346. handleClose(undefined)
  347. }}>
  348. {pinned ?
  349. <CloseIcon className={classes.iconClose} /> :
  350. <PushPinIcon />}
  351. {pinned?'Unpin':'Pin'}
  352. </MenuItem>
  353. <MenuItem onClick={() => {
  354. handleSelected(_id)
  355. handleClose(undefined)
  356. }}>
  357. <CheckBoxIcon />
  358. Select
  359. </MenuItem>
  360. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  361. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  362. Delete
  363. </MenuItem>
  364. </StyledMenu>
  365. {modal &&
  366. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  367. <div className={classes.modalDelete}>
  368. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  369. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  370. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  371. DELETE MESSAGE
  372. </Button>
  373. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  374. CANCEL
  375. </Button>
  376. </div>
  377. </div>}
  378. </div>
  379. {isSomeSelected&&<Checkbox {...label} checked={checked} sx={{color:nightMode?'#ffffff':'#00ff48','&.Mui-checked': {color: nightMode?'#ffffff':'#00ff48'}}} onClick={() => handleSelected(_id)}/>}
  380. </div>
  381. )};
  382. export default MessageRightVideo