index.tsx 12 KB

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