|
|
|
@ -7,32 +7,33 @@ import Avatar from "../Avatar"; |
|
|
|
|
import moment from "jalali-moment"; |
|
|
|
|
import StarRating from "../StarRating"; |
|
|
|
|
|
|
|
|
|
export const Comments = ({ comments }) => { |
|
|
|
|
export const Comments = ({ comments, indent }) => { |
|
|
|
|
const [list, setList] = useState([]); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
let indentComments = comments?.sort((i, j) => i.pid - j.pid); |
|
|
|
|
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: [], |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
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; |
|
|
|
|
|
|
|
|
|
if (comment.pid) { |
|
|
|
|
acc[comment.pid]?.childs?.push(cmnt); |
|
|
|
|
} else { |
|
|
|
|
result?.push(cmnt); |
|
|
|
|
} |
|
|
|
|
acc[comment?.id] = cmnt; |
|
|
|
|
|
|
|
|
|
return acc; |
|
|
|
|
}, []); |
|
|
|
|
setList(result); |
|
|
|
|
return acc; |
|
|
|
|
}, []); |
|
|
|
|
setList(result); |
|
|
|
|
} |
|
|
|
|
}, [comments]); |
|
|
|
|
|
|
|
|
|
const Comment = ({ comment }) => { |
|
|
|
@ -42,27 +43,19 @@ export const Comments = ({ comments }) => { |
|
|
|
|
<div className="flex flex-row items-end"> |
|
|
|
|
<Avatar source={comment?.userImage} size={60} rounded={true} /> |
|
|
|
|
<div className="flex flex-col"> |
|
|
|
|
<strong className="text-lg mr-2">{comment.id}</strong> |
|
|
|
|
{/* {comment.pid && ( |
|
|
|
|
<strong className="text-lg mr-2"> |
|
|
|
|
{"در پاسخ به" + |
|
|
|
|
" " + |
|
|
|
|
comments.filter( |
|
|
|
|
(commentt) => commentt.id === comment.pid |
|
|
|
|
)[0].id} |
|
|
|
|
</strong> |
|
|
|
|
)} */} |
|
|
|
|
{/* <div |
|
|
|
|
<div className="flex items-center"> |
|
|
|
|
<strong className="text-base mr-2">{comment.userId}</strong> |
|
|
|
|
<span className="text-tiny text-greenBA mr-3"> |
|
|
|
|
{comment?.userRoll || "خریدار محصول"} |
|
|
|
|
</span> |
|
|
|
|
<div className="flex flex-row items-center mr-10 font-semibold"> |
|
|
|
|
<StarRating /> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<div |
|
|
|
|
className="flex flex-row divide-x divide-gray-300 mt-4 divided items-center" |
|
|
|
|
style={{ direction: "ltr" }} |
|
|
|
|
> |
|
|
|
|
<span className="px-2 text-xs text-gray-500"> |
|
|
|
|
{comment?.product?.color} |
|
|
|
|
</span> |
|
|
|
|
<span className="px-2 text-xs text-gray-500"> |
|
|
|
|
{comment?.product?.name} |
|
|
|
|
</span> |
|
|
|
|
</div> */} |
|
|
|
|
></div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<div |
|
|
|
@ -77,14 +70,12 @@ export const Comments = ({ comments }) => { |
|
|
|
|
</span> |
|
|
|
|
</div> |
|
|
|
|
</header> |
|
|
|
|
<div className="flex flex-row py-4"> |
|
|
|
|
<div className="flex flex-row"> |
|
|
|
|
<div style={{ width: 60 }} className="min-h-full"></div> |
|
|
|
|
<div className="flex flex-1 flex-col px-3"> |
|
|
|
|
<header className="w-full flex flex-row justify-between items-center"> |
|
|
|
|
{/* <div className="flex flex-row items-center"> |
|
|
|
|
<StarRating /> |
|
|
|
|
</div> */} |
|
|
|
|
{/* <div className="flex flex-row items-center"> |
|
|
|
|
<div> </div> |
|
|
|
|
<div className="flex flex-row items-center"> |
|
|
|
|
{comment?.status === true && ( |
|
|
|
|
<> |
|
|
|
|
<img src={positiveIcon} alt="" className="w-6 ml-2" /> |
|
|
|
@ -101,7 +92,7 @@ export const Comments = ({ comments }) => { |
|
|
|
|
</span> |
|
|
|
|
</> |
|
|
|
|
)} |
|
|
|
|
</div> */} |
|
|
|
|
</div> |
|
|
|
|
</header> |
|
|
|
|
<p className="text-gray-500 h-auto leading-7 mt-2"> |
|
|
|
|
{comment?.text} |
|
|
|
@ -111,18 +102,20 @@ export const Comments = ({ comments }) => { |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
<div className="flex pr-12"> |
|
|
|
|
{comment?.childs?.map((object, index) => ( |
|
|
|
|
<Comment comment={object} key={index} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|
{indent && ( |
|
|
|
|
<div className="flex pr-12"> |
|
|
|
|
{comment?.childs?.map((object, index) => ( |
|
|
|
|
<Comment comment={object} key={index} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|
)} |
|
|
|
|
</div> |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<div className="w-full flex flex-col"> |
|
|
|
|
{list?.map((comment, index) => ( |
|
|
|
|
<div className="w-full flex flex-col divide-y divide-solid divide-gray-200"> |
|
|
|
|
{(indent ? list : comments)?.map((comment, index) => ( |
|
|
|
|
<Comment comment={comment} key={index} /> |
|
|
|
|
))} |
|
|
|
|
</div> |
|
|
|
|