import React, { useMemo, useEffect, useState } from "react"; import { connect } from "react-redux"; import userImage from "./user.svg"; import positiveIcon from "./positive.svg"; import negativeIcon from "./negative.svg"; import Avatar from "../Avatar"; import moment from "jalali-moment"; import StarRating from "../StarRating"; export const Comments = ({ comments, indent }) => { const [list, setList] = useState([]); useEffect(() => { if (indent) { let indentComments = comments?.sort((i, j) => i.pid - j.pid); let result = []; indentComments?.reduce((acc, comment) => { let cmnt = { id: comment?.id, title: comment?.title, text: comment?.text, pid: comment?.pid, childs: [], }; if (comment.pid) { acc[comment.pid]?.childs?.push(cmnt); } else { result?.push(cmnt); } acc[comment?.id] = cmnt; return acc; }, []); setList(result); } }, [comments]); const Comment = ({ comment }) => { return (
{comment?.text}