index.tsx 12 KB

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