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