chatsList.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import TimeAgo from 'javascript-time-ago'
  2. import ru from 'javascript-time-ago/locale/ru.json'
  3. import React, { useState } from 'react';
  4. import { connect } from "react-redux";
  5. import { ChatItem } from "./chatItem";
  6. import { Box, List, Fab, ListItem } from '@mui/material'
  7. import history from '../components/history';
  8. import AddIcon from '@mui/icons-material/Add';
  9. TimeAgo.addLocale(ru)
  10. const ChatsList = ({ chats }) => {
  11. const [selected, setSelected] = useState(false)
  12. const handleListItemClick = (event, id) => {
  13. setSelected(id)
  14. }
  15. return (
  16. <Box sx={{ width: '100%', bgcolor: 'background.paper' }}>
  17. <List component="nav" aria-label="main mailbox folders" sx={{
  18. width: '100%',
  19. bgcolor: 'background.paper',
  20. position: 'relative',
  21. overflow: 'auto',
  22. maxHeight: '93vh',
  23. }}>
  24. {Object.entries(chats).map(([id, chat]) => <ChatItem key={id} id={id} chat={chat} selected={selected} handle={handleListItemClick} />)}
  25. <ListItem sx={{
  26. position: 'fixed',
  27. bottom: '10px',
  28. left: '18%',
  29. }}>
  30. <Fab color="primary" aria-label="add" onClick={() => history.push("/chat")}>
  31. <AddIcon />
  32. </Fab>
  33. </ListItem>
  34. </List>
  35. </Box >
  36. )
  37. }
  38. const ConnectChatsList = connect(state => ({ chats: state.chat }))(ChatsList)
  39. export default ConnectChatsList