index.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import List from '@mui/material/List';
  2. import ListItem from '@mui/material/ListItem';
  3. import ListItemText from '@mui/material/ListItemText';
  4. import ListItemAvatar from '@mui/material/ListItemAvatar';
  5. import Avatar from '@mui/material/Avatar';
  6. import Divider from '@mui/material/Divider';
  7. import ContentCopyIcon from '@mui/icons-material/ContentCopy';
  8. import { CopyToClipboard } from 'react-copy-to-clipboard';
  9. import { makeStyles } from '@material-ui/core'
  10. import AlertInfo from '../../../../reusableComponents/AlertInfo';
  11. import { timeStampEU,firstLetter,copied,prodBaseURL } from '../../../../../helpers'
  12. import { TAllMessages } from '../../../../../typescript/redux/allMessages/types'
  13. const useStyles = makeStyles({
  14. container: {
  15. width: '100%',
  16. maxHeight: '86vh',
  17. overflowY: 'scroll',
  18. '&::-webkit-scrollbar': {
  19. width: '0.4em'
  20. },
  21. '&::-webkit-scrollbar-track': {
  22. boxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  23. webkitBoxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  24. backgroundColor: '#eceeec',
  25. },
  26. '&::-webkit-scrollbar-thumb': {
  27. backgroundColor: '#ccc8c8',
  28. },
  29. "&::-webkit-scrollbar-thumb:focus": {
  30. backgroundColor: "#959595",
  31. },
  32. "&::-webkit-scrollbar-thumb:active": {
  33. backgroundColor: "#959595",
  34. },
  35. },
  36. listItem: {
  37. '&:hover': {
  38. backgroundColor: '#f0f0f0',
  39. }
  40. },
  41. copyIcon: {
  42. color: '#54b0fc',
  43. cursor: 'pointer',
  44. '&:hover': {
  45. color: '#016cc3'
  46. },
  47. },
  48. })
  49. const TextList = ({ allMessagesMemo,value,date }: { allMessagesMemo: TAllMessages,value: string,date: any }) => {
  50. const classes = useStyles()
  51. const filteredMessagesMemo = allMessagesMemo.filter(({type}) => type === 'text')
  52. return (
  53. <>
  54. {filteredMessagesMemo.length > 0 &&
  55. <List className={classes.container}>
  56. {filteredMessagesMemo.map(({ message, createdAt, lastName, name, color, avatarUrl }) =>
  57. <div key={createdAt}>
  58. <ListItem alignItems="flex-start" className={classes.listItem}>
  59. <ListItemAvatar>
  60. <Avatar alt={name} src={avatarUrl?`${prodBaseURL}/${avatarUrl}`:undefined}
  61. sx={{ background: color, width: 38, height: 38}}>
  62. {`${firstLetter(name)}${firstLetter(lastName)}`}
  63. </Avatar>
  64. </ListItemAvatar>
  65. <ListItemText style={{ wordBreak: 'break-word',marginRight:2 }} primary={message}
  66. secondary={timeStampEU(createdAt)} secondaryTypographyProps={{color: '#020202',paddingTop:0.5}}
  67. />
  68. <CopyToClipboard onCopy={() => copied('Message')} text={message}>
  69. <ContentCopyIcon className={classes.copyIcon} fontSize='large' />
  70. </CopyToClipboard>
  71. </ListItem>
  72. <Divider variant="inset" />
  73. </div>)}
  74. </List>}
  75. {(value || date) && filteredMessagesMemo.length === 0 && <AlertInfo name={`Can not find Text by request: ${value}`} />}
  76. {!value && !date && filteredMessagesMemo.length === 0 && <AlertInfo name='You do not have Text yet!'/>}
  77. </>
  78. )
  79. }
  80. export default TextList