index.tsx 12 KB

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