import React from 'react'; import { Box } from '@chakra-ui/react'; import { useDispatch, useSelector } from 'react-redux'; import { getUserProfileData } from '../../helper/getUserProfileData'; import CommentItem from './CommentItem'; import { useEffect } from 'react'; import { setCurrentComments } from '../../store/comment/currentComments'; import { useAuth } from '../../context/auth'; const AllComment = ({ postDetail }) => { const dispatch = useDispatch(); const user = useAuth(); useEffect(() => { dispatch(setCurrentComments(postDetail.comments)); }, [postDetail.comments, dispatch]); const profileData = useSelector((state) => state.profileData.profileData); const currentComments = useSelector( (state) => state.currentComments.currentComments ); const repliedComment = (replies) => Object.values(replies).sort((a, b) => a.createdAt - b.createdAt); //ascending ordered by created at; return ( {postDetail.comments.map((comment) => ( {Object.values(comment.replies).length !== 0 && repliedComment(comment.replies).map((item) => ( ))} ))} ); }; export default AllComment;