|
@@ -1,10 +1,17 @@
|
|
import {connect} from "react-redux";
|
|
import {connect} from "react-redux";
|
|
import styled from 'styled-components';
|
|
import styled from 'styled-components';
|
|
-import {useEffect} from "react";
|
|
|
|
-import {setActiveUserAllPostsAsync, setUserDataAsync} from "../store/actionCreators/ActionCreators";
|
|
|
|
|
|
+import {useEffect, useState} from "react";
|
|
|
|
+import {
|
|
|
|
+ setActiveUserAllPosts,
|
|
|
|
+ setUserDataAsync,
|
|
|
|
+ setActiveUserAllPostsAsync
|
|
|
|
+} from "../store/actionCreators/ActionCreators";
|
|
import avatar from "../assets/img/avatarGolub.jpg";
|
|
import avatar from "../assets/img/avatarGolub.jpg";
|
|
-import Post from "./Post";
|
|
|
|
|
|
+import PostPreview from "./PostPreview";
|
|
import UserInfoBlock from "./UserInfoBlock";
|
|
import UserInfoBlock from "./UserInfoBlock";
|
|
|
|
+import ModalWindow from "./ModalWindow";
|
|
|
|
+import UserList from "./UserList";
|
|
|
|
+import SubscribeButton from "./SubscribeButton";
|
|
|
|
|
|
|
|
|
|
const UserContentWrapper = styled.div`
|
|
const UserContentWrapper = styled.div`
|
|
@@ -38,6 +45,7 @@ const UserInfoWrapper = styled.div`
|
|
const UserInfoBlockWrapper = styled.div`
|
|
const UserInfoBlockWrapper = styled.div`
|
|
display: flex;
|
|
display: flex;
|
|
justify-content: flex-start;
|
|
justify-content: flex-start;
|
|
|
|
+ align-items: center;
|
|
`
|
|
`
|
|
const AvatarWrapper = styled.div`
|
|
const AvatarWrapper = styled.div`
|
|
width: 100px;
|
|
width: 100px;
|
|
@@ -48,23 +56,47 @@ const AvatarWrapper = styled.div`
|
|
display: flex;
|
|
display: flex;
|
|
align-items: center;
|
|
align-items: center;
|
|
`
|
|
`
|
|
|
|
+const UserListWrapper = styled.div`
|
|
|
|
+ width: 30vw;
|
|
|
|
+ height: 50vh;
|
|
|
|
+ display: flex;
|
|
|
|
+`
|
|
|
|
|
|
const tempUser = "62c1cc5e4535fc62e2a185ad"; // test - should be deleted
|
|
const tempUser = "62c1cc5e4535fc62e2a185ad"; // test - should be deleted
|
|
|
|
|
|
|
|
|
|
function UserContent(props) {
|
|
function UserContent(props) {
|
|
|
|
+ const [isModal, setModal] = useState(false);
|
|
|
|
+ const [userList, setUserList] = useState("");
|
|
|
|
|
|
|
|
+ // console.log(props.activeUser?._id === props.id)
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
if (!props.activeUser) {
|
|
if (!props.activeUser) {
|
|
props.setUserDataAsync(props.id)
|
|
props.setUserDataAsync(props.id)
|
|
}
|
|
}
|
|
- if (props.activeUser && !props.activeUserPosts.length) {
|
|
|
|
|
|
+ if (props.activeUser && props.activeUserPosts === null) {
|
|
|
|
+ // props.setActiveUserAllPostsAsync(tempUser);
|
|
|
|
+
|
|
|
|
+ props.setActiveUserAllPostsAsync(props.activeUser._id)
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
- props.setActiveUserAllPostsAsync(tempUser);
|
|
|
|
- // props.setActiveUserAllPostsAsync(props.activeUser._id)
|
|
|
|
|
|
+ useEffect(()=>{
|
|
|
|
+ if(props.activeUserPosts && props.activeUserPosts[0] && props.activeUserPosts[0].owner && props.activeUser && props.activeUserPosts[0].owner._id !== props.activeUser._id ){
|
|
|
|
+ // console.log("2 useEffect")
|
|
|
|
+ props.setActiveUserAllPosts(null)
|
|
}
|
|
}
|
|
})
|
|
})
|
|
- console.log(props.activeUserPosts)
|
|
|
|
|
|
+
|
|
|
|
+ // console.log(props.activeUserPosts)
|
|
|
|
+
|
|
|
|
+ function toggleModalWindow(userList) {
|
|
|
|
+ setModal(!isModal)
|
|
|
|
+
|
|
|
|
+ setUserList(userList)
|
|
|
|
+ // console.log(props.activeUser.followers)
|
|
|
|
+ }
|
|
|
|
+// console.log(props.activeUser?.followers)
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
{props.activeUser && <UserContentWrapper>
|
|
{props.activeUser && <UserContentWrapper>
|
|
@@ -79,15 +111,31 @@ function UserContent(props) {
|
|
</AvatarBlock>
|
|
</AvatarBlock>
|
|
<UserInfoBlockWrapper>
|
|
<UserInfoBlockWrapper>
|
|
<UserInfoBlock count={props.activeUserPosts?.length} description={"posts"}/>
|
|
<UserInfoBlock count={props.activeUserPosts?.length} description={"posts"}/>
|
|
- <UserInfoBlock count={props.activeUser.followers?.length} description={"followers"}/>
|
|
|
|
- <UserInfoBlock count={props.activeUser.following?.length} description={"followings"}/>
|
|
|
|
|
|
+ <div onClick={()=>toggleModalWindow( props.activeUser.followers)}>
|
|
|
|
+ <UserInfoBlock count={props.activeUser.followers?.length} description={"followers"}/>
|
|
|
|
+ </div>
|
|
|
|
+ <div onClick={()=>toggleModalWindow( props.activeUser.following)}>
|
|
|
|
+ <UserInfoBlock count={props.activeUser.following?.length} description={"followings"}/>
|
|
|
|
+ </div>
|
|
</UserInfoBlockWrapper>
|
|
</UserInfoBlockWrapper>
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ {props.activeUser?._id === props.id && <button>fix profile</button> || <SubscribeButton followers={props.activeUser?.followers}/>}
|
|
|
|
+
|
|
|
|
+
|
|
</UserInfoWrapper>
|
|
</UserInfoWrapper>
|
|
|
|
|
|
{props.activeUserPosts &&
|
|
{props.activeUserPosts &&
|
|
<PostsContainer>
|
|
<PostsContainer>
|
|
- {props.activeUserPosts.map((post, index) => <Post activeUser={props.activeUser} postId={post._id} key={index}/>)}
|
|
|
|
|
|
+ {props.activeUserPosts.map((post, index) => <PostPreview activeUser={props.activeUser}
|
|
|
|
+ postId={post._id} key={index}/>)}
|
|
</PostsContainer>}
|
|
</PostsContainer>}
|
|
|
|
+ {isModal && <ModalWindow closeModal={toggleModalWindow}>
|
|
|
|
+ <UserListWrapper>
|
|
|
|
+ <UserList users={userList} closeModal={toggleModalWindow}/>
|
|
|
|
+ </UserListWrapper>
|
|
|
|
+ </ModalWindow>}
|
|
|
|
+
|
|
</UserContentWrapper>
|
|
</UserContentWrapper>
|
|
}
|
|
}
|
|
</>
|
|
</>
|
|
@@ -107,6 +155,7 @@ const mapDispatchToProps = (dispatch) => {
|
|
return {
|
|
return {
|
|
setUserDataAsync: (id) => dispatch(setUserDataAsync(id)),
|
|
setUserDataAsync: (id) => dispatch(setUserDataAsync(id)),
|
|
setActiveUserAllPostsAsync: (id) => dispatch(setActiveUserAllPostsAsync(id)),
|
|
setActiveUserAllPostsAsync: (id) => dispatch(setActiveUserAllPostsAsync(id)),
|
|
|
|
+ setActiveUserAllPosts: (posts) => dispatch(setActiveUserAllPosts(posts))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|