ChatsPage.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import React, { useState, useEffect } from "react";
  2. import { connect } from "react-redux";
  3. import { backURL } from "../constants";
  4. import { Link } from "react-router-dom";
  5. import { AvatarStub, color } from "../components/AvatarStub";
  6. import { actionFullMsgsByChat } from "../actions";
  7. import { actionUserFindOne, store } from "../reducers";
  8. import Button from "react-bootstrap/esm/Button";
  9. const ChatsPage = ({ chats = [], _id, msgOneChat, msgCount = 20,}) => {
  10. return (
  11. <>
  12. <div className="chatsContainer">
  13. {chats.map((chat, _id) => (
  14. <>
  15. <Link className="chatsList" to={`/main/${chat._id}`}>
  16. {chat.avatar?.url ? (
  17. <img
  18. className="smallForChat"
  19. src={backURL + chat.avatar?.url}
  20. />
  21. ) : (
  22. <AvatarStub
  23. login={
  24. chat.title !== null
  25. ? chat.title
  26. : "chat without title"
  27. }
  28. color={color()}
  29. />
  30. )}
  31. <h5 className="chatTitle">
  32. {chat.title !== null
  33. ? chat.title
  34. : "chat without title"}
  35. </h5>
  36. </Link>
  37. </>
  38. ))}
  39. <Link className="newChatButton" to="/newchat">
  40. +
  41. </Link>
  42. </div>
  43. </>
  44. );
  45. };
  46. export const CChatsPage = connect(
  47. (state) => ({
  48. chats: Object.values(state.chats).filter((el) => el._id),
  49. }), {msgOneChat : actionFullMsgsByChat}
  50. )(ChatsPage);