index.tsx 12 KB

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