index.tsx 12 KB

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