index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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:'4px 0px 4px 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. width: '100%',
  92. paddingRight:3,
  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. },
  196. tongueTwo: {
  197. content: "''",
  198. position: "absolute",
  199. width: "0",
  200. height: "0",
  201. borderLeft: "16px solid transparent",
  202. borderRight: "16px solid transparent",
  203. bottom: "0px",
  204. left: "-17px",
  205. },
  206. });
  207. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  208. interface IMessageLeftAudio {
  209. url: string,
  210. tongue: boolean,
  211. avatarUrl: string,
  212. color: string,
  213. name: string,
  214. lastName: string,
  215. createdAt: string,
  216. fullType: string,
  217. caption: string,
  218. emoji: string,
  219. emojiCompanion: string,
  220. pinned: boolean,
  221. isSomeSelected: boolean,
  222. isSelected:(_id:string) => boolean,
  223. handleSelected: (_id:string) => void,
  224. _id: string,
  225. nightMode: boolean,
  226. handleReply: (_id: string) => void,
  227. handleForward: (_id: string) => void,
  228. }
  229. const MessageLeftAudio = ({ url,tongue,avatarUrl,color,name,lastName,createdAt,fullType,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward }:IMessageLeftAudio) => {
  230. const classes = useStyles();
  231. const [anchorEl, setAnchorEl] = useState<any>(null);
  232. const [selected, setSelected] = useState<boolean>(false);
  233. const [modal,setModal] = useState<boolean>(false)
  234. const open = Boolean(anchorEl);
  235. const checked = isSelected(_id)
  236. const handleClose = (type: string | undefined): void => {
  237. if (type === 'copy') copied('Link')
  238. if (type === 'delete') setModal(true)
  239. setAnchorEl(null)
  240. setSelected(false)
  241. }
  242. const handleDeleteModal = (e: any) => {
  243. const id = e.target.id
  244. if (id === 'overlay' || id === 'cancel') return setModal(false)
  245. if (id === 'delete') {
  246. removeMessageById(_id)
  247. setModal(false)
  248. }
  249. }
  250. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  251. e.preventDefault()
  252. setAnchorEl(e.currentTarget)
  253. setSelected(true)
  254. }
  255. const handleEmojiMenu = ({ target }: any): void => {
  256. const idEmoji = target.id
  257. if (idEmoji === emoji) {
  258. updateMessageById(_id, '')
  259. } else updateMessageById(_id,idEmoji)
  260. }
  261. return (
  262. <div className={classes.container} style={{marginBottom:tongue?12:0}}>
  263. <div onContextMenu={(e) => handleContextMenu(e)}
  264. className={classes.wrapper} style={{backgroundColor: selected ? '#babdbc' : "#ffffff",pointerEvents: isSomeSelected ? 'none' : 'auto'}}>
  265. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  266. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  267. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  268. </Typography>
  269. <div className={classes.wrapperInner}>
  270. <AudioFileIcon onClick={() => handleDownload(url, fullType)}
  271. className={classes.folderIcon} fontSize='large' />
  272. <ReactAudioPlayer className={classes.player} src={url} controls />
  273. </div>
  274. <ListItemText style={{wordBreak:'break-word'}} secondary={caption} secondaryTypographyProps={{color: "#000000"}}/>
  275. <div className={classes.informationWrapper}>
  276. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  277. </div>
  278. {tongue&&<div className={classes.avatarIcon}>
  279. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  280. sx={{ background: color, width: 40, height: 40 }}>
  281. {!avatarUrl&&`${firstLetter(name)}${firstLetter(lastName)}`}
  282. </Avatar>
  283. </div>}
  284. {tongue&&<span className={classes.tongueOne} style={{borderBottom: `15px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  285. {tongue&&<span className={classes.tongueTwo} style={{borderBottom: `17px solid ${selected?'#babdbc' : "#ffffff"}`}}></span>}
  286. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  287. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  288. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  289. onClick={() => handleSelected(_id)}/></div>}
  290. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  291. anchorEl={anchorEl} open={open} onClose={handleClose}>
  292. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  293. {emojisArr.map((el:string, i:number) =>
  294. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  295. </MenuItem>
  296. <Divider />
  297. <MenuItem onClick={() => {
  298. handleReply(_id)
  299. handleClose(undefined)
  300. }}>
  301. <ReplyIcon />
  302. Reply
  303. </MenuItem>
  304. <MenuItem onClick={() => {
  305. handleForward(_id)
  306. handleClose(undefined)
  307. }}>
  308. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  309. Forward
  310. </MenuItem>
  311. <CopyToClipboard onCopy={() => handleClose('copy')} text={url}>
  312. <MenuItem>
  313. <ContentCopyIcon />
  314. Copy Link
  315. </MenuItem>
  316. </CopyToClipboard>
  317. <MenuItem onClick={() => {
  318. pinMessageById(_id, !pinned)
  319. handleClose(undefined)
  320. }}>
  321. {pinned ?
  322. <CloseIcon className={classes.iconClose} /> :
  323. <PushPinIcon />}
  324. {pinned?'Unpin':'Pin'}
  325. </MenuItem>
  326. <MenuItem onClick={() => {
  327. handleSelected(_id)
  328. handleClose(undefined)
  329. }}>
  330. <CheckBoxIcon />
  331. Select
  332. </MenuItem>
  333. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  334. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  335. Delete
  336. </MenuItem>
  337. </StyledMenu>
  338. {modal &&
  339. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  340. <div className={classes.modalDelete}>
  341. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  342. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  343. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  344. DELETE MESSAGE
  345. </Button>
  346. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  347. CANCEL
  348. </Button>
  349. </div>
  350. </div>}
  351. </div>
  352. </div>
  353. )};
  354. export default MessageLeftAudio