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 }) => { const [list, setList] = useState([]); useEffect(() => { 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.id} {/* {comment.pid && ( {"در پاسخ به" + " " + comments.filter( (commentt) => commentt.id === comment.pid )[0].id} )} */} {/*
{comment?.product?.color} {comment?.product?.name}
*/}
{moment(comment?.createdAt).locale("fa").format("YYYY/MM/DD")} {moment(comment?.createdAt).locale("fa").format("HH:mm:ss")}
{/*
*/} {/*
{comment?.status === true && ( <> برای خرید توصیه می‌کنم )} {comment?.status === false && ( <> برای خرید توصیه نمی‌کنم )}
*/}

{comment?.text}

{/*
{comment?.childs?.map((object, index) => ( ))}
); }; return (
{list?.map((comment, index) => ( ))}
); }; const mapStateToProps = (state) => ({ comments: state.book.info?.comment, }); const mapDispatchToProps = {}; export default connect(mapStateToProps, mapDispatchToProps)(Comments);