|
@@ -1,6 +1,5 @@
|
|
|
import {useEffect, useState} from "react";
|
|
|
import picture from "../assets/img/brokenPicture.png";
|
|
|
-import Carousel from "react-material-ui-carousel";
|
|
|
import AutoAwesomeMotionIcon from "@mui/icons-material/AutoAwesomeMotion";
|
|
|
import ModalWindow from "./ModalWindow";
|
|
|
import AvaLoginBlock from "./AvaLoginBlock";
|
|
@@ -8,6 +7,8 @@ import CommentsBlock from "./CommentsBlock";
|
|
|
import styled from "styled-components";
|
|
|
import LikeBlock from "./LikeBlock";
|
|
|
import {gqlOnePost} from "../shared/services&utilits/gqlRequest";
|
|
|
+import CommentMessageBlock from "./CommentMessageBlock";
|
|
|
+import ImgBlock from "./ImgBlock";
|
|
|
|
|
|
|
|
|
const PostWrapper = styled.div`
|
|
@@ -55,19 +56,21 @@ const Title = styled.p`
|
|
|
const Text = styled.p`
|
|
|
`
|
|
|
|
|
|
-function Post({postId}){
|
|
|
+
|
|
|
+function Post({postId}) {
|
|
|
const [isModal, setModal] = useState(false);
|
|
|
const [postData, setPostData] = useState(null);
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
if (!postData) {
|
|
|
gqlOnePost(postId).then(res => res.json())
|
|
|
- .then(data =>setPostData(data["data"].PostFindOne))
|
|
|
+ .then(data => setPostData(data["data"].PostFindOne))
|
|
|
}
|
|
|
}, [])
|
|
|
|
|
|
- function updatePostData(){
|
|
|
+ function updatePostData() {
|
|
|
gqlOnePost(postId).then(res => res.json())
|
|
|
- .then(data =>setPostData(data["data"].PostFindOne))
|
|
|
+ .then(data => setPostData(data["data"].PostFindOne))
|
|
|
}
|
|
|
|
|
|
|
|
@@ -75,60 +78,50 @@ function Post({postId}){
|
|
|
setModal(!isModal)
|
|
|
}
|
|
|
|
|
|
+
|
|
|
console.log(postData)
|
|
|
- const ImgBlock = ({images}) => {
|
|
|
- return (
|
|
|
- <>
|
|
|
- {!images && <img src={picture} alt={"pic"}/>}
|
|
|
- {images && images.length === 1 && <img src={images[0].url} alt={"pic"} style={{width: "100%"}}/>}
|
|
|
- {images && images.length > 1 && <div style={{width: "100%"}}>
|
|
|
- <Carousel autoPlay={false} navButtonsAlwaysVisible={true}>{
|
|
|
- images.map((item, i) => <img src={item.url} key={i} style={{width: "100%"}}
|
|
|
- alt={"picture"}/>)
|
|
|
- }
|
|
|
- </Carousel>
|
|
|
- </div>}
|
|
|
- </>
|
|
|
- )
|
|
|
- };
|
|
|
+
|
|
|
|
|
|
// console.log(post)
|
|
|
return (
|
|
|
<>
|
|
|
- {postData &&
|
|
|
- <PostWrapper onClick={() => toggleModalWindow()}>
|
|
|
- <img src={postData.images ? postData.images[0].url : picture} alt="post" style={{width: "100%"}}/>
|
|
|
- {
|
|
|
- postData.images?.length > 1 && <LogoManyImg>
|
|
|
- <AutoAwesomeMotionIcon/>
|
|
|
- </LogoManyImg>
|
|
|
- }
|
|
|
- {isModal &&
|
|
|
- <ModalWindow closeModal={toggleModalWindow}>
|
|
|
- <PicsInModalWrapper>
|
|
|
- <ImgBlock images={postData.images}/>
|
|
|
- </PicsInModalWrapper>
|
|
|
- <InfoBlockInModalWrapper>
|
|
|
-
|
|
|
- <AvaLoginWrap>
|
|
|
- <AvaLoginBlock urlAva={postData.owner.avatar} name={postData.owner.login}/>
|
|
|
- </AvaLoginWrap>
|
|
|
- <DescriptionPostWrapper>
|
|
|
- <Title>Title:{postData.title}</Title>
|
|
|
- <Text>{postData.text}</Text>
|
|
|
- </DescriptionPostWrapper>
|
|
|
-
|
|
|
- <CommentsBlock post={postData}/>
|
|
|
- {postData.likes &&
|
|
|
- <LikeBlock likes={postData.likes} postId={postData._id} updatePostData={updatePostData}/>
|
|
|
- }
|
|
|
- </InfoBlockInModalWrapper>
|
|
|
- </ModalWindow>
|
|
|
+ {postData &&
|
|
|
+ <PostWrapper onClick={() => toggleModalWindow()}>
|
|
|
+ <img src={postData.images ? postData.images[0].url : picture} alt="post" style={{width: "100%"}}/>
|
|
|
+ {
|
|
|
+ postData.images?.length > 1 && <LogoManyImg>
|
|
|
+ <AutoAwesomeMotionIcon/>
|
|
|
+ </LogoManyImg>
|
|
|
+ }
|
|
|
+ {isModal &&
|
|
|
+ <ModalWindow closeModal={toggleModalWindow}>
|
|
|
+ <PicsInModalWrapper>
|
|
|
+ <ImgBlock images={postData.images}/>
|
|
|
+ </PicsInModalWrapper>
|
|
|
+ <InfoBlockInModalWrapper>
|
|
|
+
|
|
|
+ <AvaLoginWrap>
|
|
|
+ <AvaLoginBlock urlAva={postData.owner.avatar} name={postData.owner.login}/>
|
|
|
+ </AvaLoginWrap>
|
|
|
+ <DescriptionPostWrapper>
|
|
|
+ <Title>Title:{postData.title}</Title>
|
|
|
+ <Text>{postData.text}</Text>
|
|
|
+ </DescriptionPostWrapper>
|
|
|
+
|
|
|
+ <CommentsBlock post={postData}/>
|
|
|
+ {postData.likes &&
|
|
|
+ <LikeBlock likes={postData.likes} postId={postData._id} updatePostData={updatePostData}/>
|
|
|
+ }
|
|
|
+
|
|
|
+ <CommentMessageBlock postId={postId} updatePostData={updatePostData}/>
|
|
|
+
|
|
|
+ </InfoBlockInModalWrapper>
|
|
|
+ </ModalWindow>
|
|
|
+ }
|
|
|
+ </PostWrapper>
|
|
|
}
|
|
|
- </PostWrapper>
|
|
|
- }
|
|
|
</>
|
|
|
)
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
export default Post;
|