index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 AudioFileIcon from '@mui/icons-material/AudioFile';
  7. import ReactAudioPlayer from 'react-audio-player';
  8. import Button from '@mui/material/Button';
  9. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  10. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  11. import Menu from '@mui/material/Menu';
  12. import MenuItem from '@mui/material/MenuItem';
  13. import Divider from '@mui/material/Divider';
  14. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  15. import Checkbox from '@mui/material/Checkbox';
  16. import PushPinIcon from '@mui/icons-material/PushPin';
  17. import CloseIcon from '@mui/icons-material/Close';
  18. import ReplyIcon from '@mui/icons-material/Reply';
  19. import Avatar from '@mui/material/Avatar';
  20. import { CopyToClipboard } from 'react-copy-to-clipboard';
  21. import { removeMessageById,updateMessageById,pinMessageById } from "../../../../../../api-data";
  22. import { prodAwsS3,timeStampMessage,handleDownload,copied,emojisArr,slicedWord,firstLetter } from '../../../../../../helpers'
  23. const StyledMenu = styled((props:any) => (
  24. <Menu
  25. elevation={0}
  26. anchorOrigin={{
  27. vertical: 'top',
  28. horizontal: 'right',
  29. }}
  30. transformOrigin={{
  31. vertical: 'bottom',
  32. horizontal: 'right',
  33. }}
  34. {...props}
  35. />
  36. ))(({ theme }:any) => ({
  37. '& .MuiPaper-root': {
  38. borderRadius: 10,
  39. marginTop: theme.spacing(0),
  40. minWidth: 220,
  41. color:
  42. theme.palette.mode === 'light' ? 'rgb(55, 65, 81)' : theme.palette.grey[500],
  43. boxShadow:
  44. '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',
  45. '& .MuiMenu-list': {
  46. padding: '4px 4px',
  47. },
  48. '& .MuiMenuItem-root': {
  49. marginBottom: theme.spacing(1),
  50. '& .MuiSvgIcon-root': {
  51. fontSize: 21,
  52. color: theme.palette.text.secondary,
  53. marginRight: theme.spacing(2),
  54. }
  55. },
  56. },
  57. }));
  58. const useStyles = makeStyles({
  59. container: {
  60. display: "flex",
  61. alignItems: 'flex-start',
  62. alignContent: 'flex-start',
  63. flexDirection:'column',
  64. borderRadius: 7,
  65. position: 'relative',
  66. padding:'10px 0px 10px 22px'
  67. },
  68. wrapper: {
  69. position: 'relative',
  70. display: 'flex',
  71. alignItems: 'start',
  72. alignContent: 'start',
  73. flexDirection: 'column',
  74. padding: 5,
  75. width:350,
  76. borderRadius: 7,
  77. },
  78. wrapperInner: {
  79. display: 'flex',
  80. alignItems: 'center',
  81. alignContent: 'center',
  82. width: '100%',
  83. cursor: 'pointer',
  84. padding:'10px 0px',
  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. color: '#414141',
  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. right: -40,
  139. },
  140. emojiCompanionTitle: {
  141. position: "absolute",
  142. fontSize: "1.7em",
  143. fontWeight:600,
  144. bottom: '2.2rem',
  145. right: -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. left: -64,
  178. top: -10,
  179. pointerEvents: 'auto'
  180. },
  181. avatarIcon: {
  182. position: 'absolute',
  183. left: -54,
  184. bottom: 10,
  185. },
  186. tongueOne: {
  187. content: "''",
  188. position: "absolute",
  189. width: "0",
  190. height: "0",
  191. borderLeft: "15px solid transparent",
  192. borderRight: "15px solid transparent",
  193. bottom: '0px',
  194. left: "-15px",
  195. zIndex:1
  196. },
  197. tongueTwo: {
  198. content: "''",
  199. position: "absolute",
  200. width: "0",
  201. height: "0",
  202. borderLeft: "16px solid transparent",
  203. borderRight: "16px solid transparent",
  204. bottom: "0px",
  205. left: "-17px",
  206. zIndex:1
  207. },
  208. });
  209. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  210. interface IMessageLeftAudio {
  211. url: string,
  212. tongue: boolean,
  213. avatarUrl: string,
  214. color: string,
  215. name: string,
  216. lastName: string,
  217. createdAt: string,
  218. fullType: string,
  219. caption: string,
  220. emoji: string,
  221. emojiCompanion: string,
  222. pinned: boolean,
  223. isSomeSelected: boolean,
  224. isSelected:(_id:string) => boolean,
  225. handleSelected: (_id:string) => void,
  226. _id: string,
  227. nightMode: boolean,
  228. handleReply: (_id: string) => void,
  229. handleForward: (_id: string) => void,
  230. }
  231. const MessageLeftAudio = ({ url,tongue,avatarUrl,color,name,lastName,createdAt,fullType,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward }:IMessageLeftAudio) => {
  232. const classes = useStyles();
  233. const [anchorEl, setAnchorEl] = useState<any>(null);
  234. const [selected, setSelected] = useState<boolean>(false);
  235. const [modal,setModal] = useState<boolean>(false)
  236. const open = Boolean(anchorEl);
  237. const checked = isSelected(_id)
  238. const handleClose = (type: string | undefined): void => {
  239. if (type === 'copy') copied('Link')
  240. if (type === 'delete') setModal(true)
  241. setAnchorEl(null)
  242. setSelected(false)
  243. }
  244. const handleDeleteModal = (e: any) => {
  245. const id = e.target.id
  246. if (id === 'overlay' || id === 'cancel') return setModal(false)
  247. if (id === 'delete') {
  248. removeMessageById(_id)
  249. setModal(false)
  250. }
  251. }
  252. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  253. e.preventDefault()
  254. setAnchorEl(e.currentTarget)
  255. setSelected(true)
  256. }
  257. const handleEmojiMenu = ({ target }: any): void => {
  258. const idEmoji = target.id
  259. if (idEmoji === emoji) {
  260. updateMessageById(_id, '')
  261. } else updateMessageById(_id,idEmoji)
  262. }
  263. return (
  264. <div className={classes.container}>
  265. <div onContextMenu={(e) => handleContextMenu(e)}
  266. className={classes.wrapper} style={{backgroundColor: selected ? '#babdbc' : "#ffffff",pointerEvents: isSomeSelected ? 'none' : 'auto'}}>
  267. <Typography style={{color: "#00b333"}} 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}>{timeStampMessage(createdAt)}</div>
  279. </div>
  280. {tongue&&<div className={classes.avatarIcon}>
  281. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  282. sx={{ background: color, width: 40, height: 40 }}>
  283. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  284. </Avatar>
  285. </div>}
  286. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  287. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  288. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  289. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  290. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  291. onClick={() => handleSelected(_id)}/></div>}
  292. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  293. anchorEl={anchorEl} open={open} onClose={handleClose}>
  294. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  295. {emojisArr.map((el:string, i:number) =>
  296. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  297. </MenuItem>
  298. <Divider />
  299. <MenuItem onClick={() => {
  300. handleReply(_id)
  301. handleClose(undefined)
  302. }}>
  303. <ReplyIcon />
  304. Reply
  305. </MenuItem>
  306. <MenuItem onClick={() => {
  307. handleForward(_id)
  308. handleClose(undefined)
  309. }}>
  310. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  311. Forward
  312. </MenuItem>
  313. <CopyToClipboard onCopy={() => handleClose('copy')} text={url}>
  314. <MenuItem>
  315. <ContentCopyIcon />
  316. Copy Link
  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 MessageLeftAudio