index.tsx 12 KB

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