index.tsx 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import ImageList from '@mui/material/ImageList';
  2. import { makeStyles } from '@material-ui/core'
  3. import { useEffect } from 'react';
  4. import MediaListItem from './MediaListItem';
  5. import AlertInfo from '../../../../reusableComponents/AlertInfo';
  6. import { filteredMessages,handleSort } from '../../../../../helpers'
  7. import { TAllMessages } from '../../../../../typescript/redux/allMessages/types'
  8. const useStyles = makeStyles({
  9. container: {
  10. width: '100%',
  11. maxHeight: '86vh',
  12. overflowY: 'scroll',
  13. '&::-webkit-scrollbar': {
  14. width: '0.4em'
  15. },
  16. '&::-webkit-scrollbar-track': {
  17. boxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  18. webkitBoxShadow: 'inset 0 0 6px rgba(0,0,0,0.00)',
  19. backgroundColor: '#eceeec',
  20. },
  21. '&::-webkit-scrollbar-thumb': {
  22. backgroundColor: '#ccc8c8',
  23. },
  24. "&::-webkit-scrollbar-thumb:focus": {
  25. backgroundColor: "#959595",
  26. },
  27. "&::-webkit-scrollbar-thumb:active": {
  28. backgroundColor: "#959595",
  29. },
  30. },
  31. })
  32. interface IMediaList {
  33. messagesMemo: TAllMessages,
  34. value: string,
  35. date: any,
  36. setDisabled: React.Dispatch<boolean>,
  37. sort: boolean,
  38. handleScrollToTheMessage:(_id:string,companionId:string) => void
  39. }
  40. const MediaList = ({ messagesMemo,value,date,sort,setDisabled,handleScrollToTheMessage }: IMediaList) => {
  41. const classes = useStyles()
  42. const filtered = messagesMemo.filter(({type}) => type === 'image')
  43. const filteredAndSorted = filteredMessages(handleSort('createdAt', filtered, sort), date, value)
  44. useEffect(() => {
  45. setDisabled(filtered.length > 0?false:true)
  46. }, [filtered, setDisabled])
  47. return (
  48. <>
  49. {filteredAndSorted.length > 0 &&
  50. <ImageList className={classes.container} cols={3} rowHeight={164}>
  51. {filteredAndSorted.map(({message,createdAt,fullType,updatedAt,_id,companionId}) =>
  52. <MediaListItem key={createdAt} message={message} fullType={fullType}
  53. updatedAt={updatedAt} handleScrollToTheMessage={handleScrollToTheMessage} id={_id} companionId={companionId}/>)}
  54. </ImageList>}
  55. {(value || date) && filteredAndSorted.length === 0 && <AlertInfo name={`Can not find Media by request: ${value}`} />}
  56. {!value && !date && filteredAndSorted.length === 0 && <AlertInfo name='You do not have Media yet!'/>}
  57. </>
  58. )
  59. }
  60. export default MediaList