index.tsx 12 KB

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