index.tsx 10 KB

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