index.tsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 { makeStyles } from '@material-ui/core'
  9. import AlertInfo from '../../../../reusableComponents/AlertInfo';
  10. import { timeStampEU,firstLetter,prodAwsS3 } from '../../../../../helpers'
  11. import { TAllMessages } from '../../../../../typescript/redux/allMessages/types'
  12. const useStyles = makeStyles({
  13. container: {
  14. width: '100%',
  15. maxHeight: '88vh',
  16. overflowY: 'scroll',
  17. position: 'absolute',
  18. animationDuration: '0.2s',
  19. animationDirection: 'normal',
  20. animation: `$moveElement`,
  21. '&::-webkit-scrollbar': {
  22. width: '0.4em'
  23. },
  24. '&::-webkit-scrollbar-track': {
  25. boxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  26. webkitBoxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  27. backgroundColor: '#eceeec',
  28. },
  29. '&::-webkit-scrollbar-thumb': {
  30. backgroundColor: '#ccc8c8',
  31. },
  32. "&::-webkit-scrollbar-thumb:focus": {
  33. backgroundColor: "#959595",
  34. },
  35. "&::-webkit-scrollbar-thumb:active": {
  36. backgroundColor: "#959595",
  37. },
  38. },
  39. listItem: {
  40. cursor:'pointer',
  41. '&:hover': {
  42. backgroundColor: '#f0f0f0',
  43. }
  44. },
  45. folderIcon: {
  46. margin: 'auto 0px',
  47. color: 'rgba(0, 0, 0, 0.5)',
  48. },
  49. '@keyframes moveElement': {
  50. '0%': { left: '-100%'},
  51. '100%': { left: '0%'},
  52. },
  53. })
  54. interface ITextList {
  55. filteredAndSortedMessages: TAllMessages,
  56. value: string,
  57. date: any,
  58. handleScrollToTheMessage:(_id:string,companionId:string) => void
  59. }
  60. const TextList = ({ filteredAndSortedMessages,value,date,handleScrollToTheMessage }: ITextList) => {
  61. const classes = useStyles()
  62. return (
  63. <>
  64. {filteredAndSortedMessages.length > 0 &&
  65. <List className={classes.container}>
  66. {filteredAndSortedMessages.map(({ message, createdAt, lastName, name, color, avatarUrl,_id,companionId }) =>
  67. <div key={createdAt}>
  68. <ListItem onClick={() => handleScrollToTheMessage(_id,companionId)}
  69. alignItems="flex-start" className={classes.listItem}>
  70. <ListItemAvatar>
  71. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  72. sx={{ background: color, width: 40, height: 40}}>
  73. {`${firstLetter(name)}${firstLetter(lastName)}`}
  74. </Avatar>
  75. </ListItemAvatar>
  76. <ListItemText style={{ wordBreak: 'break-word',marginRight:2 }} primary={message}
  77. secondary={timeStampEU(createdAt)} secondaryTypographyProps={{color: '#020202',paddingTop:0.5}}
  78. />
  79. <ContentCopyIcon className={classes.folderIcon} fontSize='large' />
  80. </ListItem>
  81. <Divider variant="inset" />
  82. </div>)}
  83. </List>}
  84. {(value || date) && filteredAndSortedMessages.length === 0 && <AlertInfo name={`Can not find Text by request: ${value}`} />}
  85. {!value && !date && filteredAndSortedMessages.length === 0 && <AlertInfo name='You do not have Text yet!'/>}
  86. </>
  87. )
  88. }
  89. export default TextList