index.tsx 12 KB

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