index.tsx 12 KB

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