index.tsx 11 KB

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