import React, { useEffect, useState } from "react"; import { connect } from "react-redux"; import { actionFullChatList, actionChatsCount } from "../actions"; import { backURL } from "../constants"; import { Link } from "react-router-dom"; import { AvatarStub, color } from "../components/AvatarStub"; const ChatsAside = ({ chats = [], auth, ownerChats }) => { const [chatBlock, setChatBlock] = useState(0); useEffect(() => { const userId = auth.payload?.sub?.id; if (userId) { ownerChats(userId); } return function cleanUp() {}; }, [chatBlock]); return ( <>
{chats.map((chat, _id) => ( <>
{chat.avatar?.url ? ( ) : ( )}
{chat.title !== null ? chat.title : "chat without title"}

{chat.lastMessage?.text.length > parseInt("30") ? chat.lastMessage?.text.substr( 0, 30 ) + "..." : chat.lastMessage?.text.substr( 0, 30 )}

))} +
); }; export const CChatsAside = connect( (state) => ({ auth: state.auth, chats: Object.values(state.chats).filter((el) => el._id), }), { ownerChats: actionFullChatList } )(ChatsAside);