index.tsx 11 KB

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