index.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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 LibraryMusicIcon from '@mui/icons-material/LibraryMusic';
  8. import FolderIcon from '@mui/icons-material/Folder';
  9. import ImageIcon from '@mui/icons-material/Image';
  10. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  11. import VideoLibraryIcon from '@mui/icons-material/VideoLibrary';
  12. import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
  13. import Menu from '@mui/material/Menu';
  14. import MenuItem from '@mui/material/MenuItem';
  15. import Divider from '@mui/material/Divider';
  16. import CheckBoxIcon from '@mui/icons-material/CheckBox';
  17. import Checkbox from '@mui/material/Checkbox';
  18. import PushPinIcon from '@mui/icons-material/PushPin';
  19. import CloseIcon from '@mui/icons-material/Close';
  20. import ReplyIcon from '@mui/icons-material/Reply';
  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. modalDelete: {
  108. background: '#ffffff',
  109. position: 'absolute',
  110. content:'',
  111. width: '20%',
  112. height:'auto',
  113. left: '40%',
  114. bottom: '48.5%',
  115. borderRadius: 10,
  116. padding: 10,
  117. display: 'flex',
  118. flexDirection:'column'
  119. },
  120. overlay: {
  121. position: 'fixed',
  122. top: 0,
  123. left: 0,
  124. width: '100vw',
  125. height: '100vh',
  126. zIndex: 100,
  127. backgroundColor: 'rgba(104, 105, 104, 0.6)',
  128. overflowY: 'hidden',
  129. },
  130. emojiTitle: {
  131. position: "absolute",
  132. fontSize: "1.7em",
  133. fontWeight:600,
  134. bottom: '0.2rem',
  135. right: -40,
  136. },
  137. emojiCompanionTitle: {
  138. position: "absolute",
  139. fontSize: "1.7em",
  140. fontWeight:600,
  141. bottom: '2.2rem',
  142. right: -40,
  143. },
  144. emoji: {
  145. cursor: 'pointer',
  146. fontSize: '1.7rem',
  147. transition: 'all 0.3s',
  148. '&:hover': {
  149. transform: 'scale(1.5)'
  150. }
  151. },
  152. emojiActive: {
  153. cursor: 'pointer',
  154. fontSize: '1.2rem',
  155. animation: `$emoji 0.6s ease-out`,
  156. animationDirection: 'forwards',
  157. animationIterationCount: 1,
  158. },
  159. '@keyframes emoji': {
  160. '5%': { transform: 'translateY(1rem)'},
  161. '10%': { transform: 'translateY(0) scale(1)',opacity: 1},
  162. '50%': { transform: 'translateY(-4rem) scale(1.5) rotateY(90deg)'},
  163. '80%': {opacity: 0},
  164. '100%': {transform: 'translateY(-8rem) scale(2) rotateY(180deg)',opacity: 0},
  165. },
  166. iconClose: {
  167. '&:hover': {
  168. transform: 'rotate(180deg)',
  169. transition: 'all 250ms ease-out ',
  170. }
  171. },
  172. checkboxSelect: {
  173. position: 'absolute',
  174. left: -64,
  175. bottom: -10,
  176. pointerEvents: 'auto'
  177. },
  178. folderIcon: {
  179. color: '#26afee',
  180. cursor: 'pointer',
  181. '&:hover': {
  182. color: '#49c1f8'
  183. },
  184. },
  185. column: {
  186. position: 'absolute',
  187. content: '',
  188. width: 2,
  189. left:43,
  190. top:'10%',
  191. height:'80%',
  192. backgroundColor: '#26afee',
  193. },
  194. });
  195. const label = { inputProps: { 'aria-label': 'Checkbox demo' } };
  196. interface IMessageLeftForward {
  197. url: string,
  198. message: string,
  199. name: string,
  200. lastName: string,
  201. forwardName:string,
  202. forwardLastName:string,
  203. createdAt: string,
  204. caption: string,
  205. emoji: string,
  206. emojiCompanion: string,
  207. pinned: boolean,
  208. isSomeSelected: boolean,
  209. isSelected:(_id:string) => boolean,
  210. handleSelected: (_id:string) => void,
  211. _id: string,
  212. nightMode: boolean,
  213. handleReply: (_id: string) => void,
  214. handleForward: (_id: string) => void,
  215. handleScrollToTheChat: (_id:string) => void,
  216. fullType: string
  217. }
  218. const MessageLeftForward = ({url,message,name,lastName,forwardName,forwardLastName,createdAt,caption,emoji,emojiCompanion,pinned,isSomeSelected,isSelected,handleSelected,_id,nightMode,handleReply,handleForward,handleScrollToTheChat,fullType}:IMessageLeftForward) => {
  219. const classes = useStyles();
  220. const [anchorEl, setAnchorEl] = useState<any>(null);
  221. const [selected, setSelected] = useState<boolean>(false);
  222. const [modal,setModal] = useState<boolean>(false)
  223. const open = Boolean(anchorEl);
  224. const checked = isSelected(_id)
  225. const handleClose = (type: string | undefined): void => {
  226. if (type === 'copy') copied('Message')
  227. if (type === 'delete') setModal(true)
  228. setAnchorEl(null)
  229. setSelected(false)
  230. }
  231. const handleDeleteModal = (e: any) => {
  232. const id = e.target.id
  233. if (id === 'overlay' || id === 'cancel') return setModal(false)
  234. if (id === 'delete') {
  235. removeMessageById(_id)
  236. setModal(false)
  237. }
  238. }
  239. const handleContextMenu = (e: React.MouseEvent<HTMLDivElement>):void => {
  240. e.preventDefault()
  241. setAnchorEl(e.currentTarget)
  242. setSelected(true)
  243. }
  244. const handleEmojiMenu = ({ target }: any): void => {
  245. const idEmoji = target.id
  246. if (idEmoji === emoji) {updateMessageById(_id,'')
  247. } else updateMessageById(_id,idEmoji)
  248. }
  249. const handleClickIcon = (e: any) => {
  250. e.stopPropagation()
  251. handleDownload(url, fullType)
  252. }
  253. return (
  254. <div className={classes.container}>
  255. <div onContextMenu={(e) => handleContextMenu(e)} className={classes.wrapper}
  256. style={{backgroundColor:selected?'#babdbc':'#ffffff',pointerEvents:isSomeSelected?'none':'auto'}}>
  257. <Typography style={{color: "#00b333"}} variant="h6" align="right">
  258. {`${firstLetter(name)}${slicedWord(name, 15, 1)}
  259. ${firstLetter(lastName)}${slicedWord(lastName, 15, 1)}`}
  260. </Typography>
  261. <div className={classes.wrapperInner}>
  262. {fullType === null &&<CopyToClipboard onCopy={() => copied('Message')} text={`Message: ${message} , Caption: ${caption}`}>
  263. <ContentCopyIcon className={classes.folderIcon} fontSize='large'/>
  264. </CopyToClipboard>}
  265. {fullType&&fullType.includes('audio') &&<LibraryMusicIcon onClick={handleClickIcon}
  266. className={classes.folderIcon} fontSize='large' />}
  267. {fullType&&fullType.includes('video') &&<VideoLibraryIcon onClick={handleClickIcon}
  268. className={classes.folderIcon} fontSize='large' />}
  269. {fullType&&fullType.includes('image') &&<ImageIcon onClick={handleClickIcon}
  270. className={classes.folderIcon} fontSize='large' />}
  271. {fullType && fullType.includes('application') && <FolderIcon onClick={handleClickIcon}
  272. className={classes.folderIcon} fontSize='large' />}
  273. <div className={classes.column}></div>
  274. <div className={classes.wrapperInnerMessage} onClick={() => handleScrollToTheChat('oldId')}>
  275. <Typography style={{color: "#26afee"}} variant="h6" align="right">
  276. {`Forwarded from ${firstLetter(forwardName)}${slicedWord(forwardName, 15, 1)}
  277. ${firstLetter(forwardLastName)}${slicedWord(forwardLastName, 15, 1)}`}
  278. </Typography>
  279. <ListItemText primary={message} primaryTypographyProps={{ color: "#000000" }}
  280. secondary={caption} secondaryTypographyProps={{color: "#7a7a7a"}}/>
  281. {/* <ListItemText primary={caption} primaryTypographyProps={{color: "#7a7a7a"}}/> */}
  282. </div>
  283. </div>
  284. <ListItemText primary={message} primaryTypographyProps={{ color: "#000000" }}
  285. secondary={caption} secondaryTypographyProps={{color: "#7a7a7a"}}/>
  286. {/* <ListItemText primary={message} primaryTypographyProps={{ color: "#000000" }} />
  287. <ListItemText primary={caption} primaryTypographyProps={{color: "#7a7a7a"}}/> */}
  288. <div className={classes.time}>{timeStampMessage(createdAt)}</div>
  289. {emojiCompanion && <div className={classes.emojiCompanionTitle}>{emojisArr[Number(emojiCompanion)]}</div>}
  290. {emoji && <div className={classes.emojiTitle}>{emojisArr[Number(emoji)]}</div>}
  291. {isSomeSelected && <div className={classes.checkboxSelect}><Checkbox {...label} checked={checked} sx={{ color: nightMode ? '#ffffff' : '#00ff48', '&.Mui-checked': { color: nightMode ? '#ffffff' : '#00ff48' } }}
  292. onClick={() => handleSelected(_id)}/></div>}
  293. <StyledMenu id="demo-positioned-menu" aria-labelledby="demo-positioned-button"
  294. anchorEl={anchorEl} open={open} onClose={handleClose}>
  295. <MenuItem onClick={handleEmojiMenu} style={{ cursor: 'none' }} >
  296. {emojisArr.map((el:string, i:number) =>
  297. <div key={el} className={emoji === String(i)?classes.emojiActive:classes.emoji} id={String(i)}>{el}</div>)}
  298. </MenuItem>
  299. <Divider />
  300. <MenuItem onClick={() => {
  301. handleReply(_id)
  302. handleClose(undefined)
  303. }}>
  304. <ReplyIcon />
  305. Reply
  306. </MenuItem>
  307. <MenuItem onClick={() => {
  308. handleForward(_id)
  309. handleClose(undefined)
  310. }}>
  311. <ReplyIcon style={{transform :'rotateY(180deg)'}} />
  312. Forward
  313. </MenuItem>
  314. <CopyToClipboard onCopy={() => handleClose('copy')} text={`Message: ${message} , Caption: ${caption}`}>
  315. <MenuItem>
  316. <ContentCopyIcon />
  317. Copy Text
  318. </MenuItem>
  319. </CopyToClipboard>
  320. <MenuItem onClick={() => {
  321. pinMessageById(_id, !pinned)
  322. handleClose(undefined)
  323. }}>
  324. {pinned ?
  325. <CloseIcon className={classes.iconClose} /> :
  326. <PushPinIcon />}
  327. {pinned?'Unpin':'Pin'}
  328. </MenuItem>
  329. <MenuItem onClick={() => {
  330. handleSelected(_id)
  331. handleClose(undefined)
  332. }}>
  333. <CheckBoxIcon />
  334. Select
  335. </MenuItem>
  336. <MenuItem style={{color:'#f02a2a'}} onClick={() => handleClose('delete')}>
  337. <DeleteOutlineIcon style={{color:'#f02a2a'}}/>
  338. Delete
  339. </MenuItem>
  340. </StyledMenu>
  341. {modal &&
  342. <div onClick={handleDeleteModal} className={classes.overlay} id='overlay'>
  343. <div className={classes.modalDelete}>
  344. <h3 style={{color: '#2c2c2c'}}>Delete message</h3>
  345. <p style={{ color: '#050505' }}>Are you sure you want to delete message?</p>
  346. <Button id='delete' variant="text" color="error" style={{fontWeight:500,fontSize:22}}>
  347. DELETE MESSAGE
  348. </Button>
  349. <Button id='cancel' variant="text" style={{fontWeight:500,fontSize:22}}>
  350. CANCEL
  351. </Button>
  352. </div>
  353. </div>}
  354. </div>
  355. </div>
  356. )};
  357. export default MessageLeftForward