index.tsx 9.9 KB

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