diff --git a/src/Components/Article/RightColumn.jsx b/src/Components/Article/RightColumn.jsx index 34de775b..bf06aaf0 100644 --- a/src/Components/Article/RightColumn.jsx +++ b/src/Components/Article/RightColumn.jsx @@ -1,24 +1,30 @@ -import React, {useContext, useState} from 'react'; +import React, {useContext, useState, useEffect } from 'react'; import {PageLinks, StyledRightContainer, AlignContent, SideUserContainer, PostContainer} from '../../Layout/Container/styledArticle'; import {SquareImage, CircleImage} from '../../Layout/Image/styledImage'; import {UserInfo, PostText, Subtitle} from '../../Layout/Text/styledText'; import {ArticleBtn} from '../../Layout/Button/styledButton'; import {ArticleLink, ArticleLinkColor} from '../../Layout/ATag/styledATag'; -import {MdBookmarkBorder} from 'react-icons/md'; +import {MdBookmarkBorder, MdClose} from 'react-icons/md'; +import {BiCheckShield, BiDotsHorizontalRounded} from 'react-icons/bi'; import { MarginTop } from '../../Layout/Margin/styledMargin'; import { ArticleInput } from '../../Layout/Input/styledInput'; import { Link } from 'react-router-dom'; import { useHistory } from 'react-router-dom'; import { GlobalState } from '../../GlobalState'; +import { useParams } from 'react-router-dom'; +import axios from 'axios'; const RightColumn = ({user, articles}) => { const history = useHistory(); - const uri = window.location.pathname; + // const uri = window.location.pathname; const state = useContext(GlobalState); const [isLoggedIn] = state.userAPI.isLoggedIn; const [search, setSearch] = useState('') + const [viewComment, setViewComment] = useState(true) + const [comments, setComments] = useState({comments: []}) + const param = useParams() const shuffleArray = (arr) => arr.sort(() => 0.5 - Math.random()); const recentPosts = shuffleArray(articles) @@ -36,7 +42,82 @@ const RightColumn = ({user, articles}) => { const handleClick= async (e) => { history.push(`/${e}`) } + + useEffect(() => { + const id = param.id + + if (id) { + const getComments = async () => { + const res = await axios.get(`/api/articles/${id}/comments`) + let filteredComments = res.data.comments.filter((comment) => { + return comment.blog === id; + }); + setComments({comments: filteredComments}); + } + getComments() + } + }, [param.id]) + return ( + <> + { + viewComment ? + + + + + Responses ({comments.comments.length}) + + + + + + + + + + + Name + + Cancel + Respond + + + Most Relevant + Most Recent + + + { + comments !== undefined && + comments.comments.length !== 0 ? + <> + {comments.comments.map(comment => { + return ( + + + + {comment.name} Reference towards the blog writer + minutes ago + + + Settings Icon + + + {comment.comment} + + + like + Reply + + + )})} + > + : + <>No Comments> + } + + : {!isLoggedIn ? @@ -97,7 +178,9 @@ const RightColumn = ({user, articles}) => { Terms About - + + } + > ) }
minutes ago