index.tsx 12 KB

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