index.tsx 10 KB

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