index.tsx 12 KB

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