index.tsx 12 KB

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