index.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 { TMessages } from '../../../../../../typescript/redux/messages/types'
  12. const useStyles = makeStyles({
  13. container: {
  14. position: 'absolute',
  15. animationDuration: '0.2s',
  16. animationDirection: 'normal',
  17. animation: `$moveElement`,
  18. },
  19. listItem: {
  20. cursor:'pointer',
  21. '&:hover': {
  22. backgroundColor: '#f0f0f0',
  23. }
  24. },
  25. folderIcon: {
  26. margin: 'auto 0px',
  27. color: 'rgba(0, 0, 0, 0.5)',
  28. },
  29. '@keyframes moveElement': {
  30. '0%': { left: '100%'},
  31. '100%': { left: '0%'},
  32. },
  33. })
  34. interface ITextList {
  35. openPinned: boolean,
  36. filteredAndSorted: TMessages,
  37. handleScrollToTheMessage: (_id:string) => void,
  38. }
  39. const TextList = ({ filteredAndSorted,handleScrollToTheMessage,openPinned }: ITextList) => {
  40. const classes = useStyles()
  41. return filteredAndSorted.length > 0 ?(
  42. <List className={classes.container}>
  43. {filteredAndSorted.map(({ message, createdAt, lastName, name, color, avatarUrl,_id }) =>
  44. <div key={createdAt}>
  45. <ListItem onClick={() => handleScrollToTheMessage(_id)}
  46. alignItems="flex-start" className={classes.listItem}>
  47. <ListItemAvatar>
  48. <Avatar alt={name} src={avatarUrl?`${prodAwsS3}/${avatarUrl}`:undefined}
  49. sx={{ background: color, width: 38, height: 38}}>
  50. {`${firstLetter(name)}${firstLetter(lastName)}`}
  51. </Avatar>
  52. </ListItemAvatar>
  53. <ListItemText style={{ wordBreak: 'break-word',marginRight:2 }} primary={message}
  54. secondary={timeStampEU(createdAt)} secondaryTypographyProps={{color: '#020202',paddingTop:0.5}}/>
  55. <ContentCopyIcon className={classes.folderIcon} fontSize='large' />
  56. </ListItem>
  57. <Divider variant="inset" />
  58. </div>)}
  59. </List>
  60. ): <AlertInfo name={`You do not have ${openPinned&&'Pinned'} Text yet!`}/>
  61. }
  62. export default TextList