From 5fc14c682d43d82135abeb2deb248e29edb468b8 Mon Sep 17 00:00:00 2001 From: Reza_ashrafi Date: Mon, 10 Jan 2022 17:28:42 +0330 Subject: [PATCH] reza added utils --- src/components/Comments/index.js | 3 ++- src/redux/data.js | 11 +++++++++++ src/utils/comments.js | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/utils/comments.js diff --git a/src/components/Comments/index.js b/src/components/Comments/index.js index 875efab..16175e8 100644 --- a/src/components/Comments/index.js +++ b/src/components/Comments/index.js @@ -1,9 +1,10 @@ import React from 'react' import { connect } from 'react-redux'; +import { connectToParent } from '../../utils/comments'; import userImage from './user.svg'; export const Comments = ({comments}) => { - + connectToParent(comments); return (
diff --git a/src/redux/data.js b/src/redux/data.js index e3d1931..515b11d 100644 --- a/src/redux/data.js +++ b/src/redux/data.js @@ -25,6 +25,7 @@ import SimpleCalendar from '../components/Calendar'; import Footer from "../components/Footer"; import SimpleDatePicker from "../components/SimpleDatePicker"; import RangeDatePicker from '../components/RangeDatePicker'; +import Comments from "../components/Comments"; const components = [ { @@ -499,6 +500,16 @@ const components = [ code: null, }, }, + { + name: "Comments", + author: "Ashrafi", + props: [], + content: { + name: "Comments", + component: , + code: null, + }, + }, ]; export default components; diff --git a/src/utils/comments.js b/src/utils/comments.js new file mode 100644 index 0000000..6d64ddb --- /dev/null +++ b/src/utils/comments.js @@ -0,0 +1,16 @@ +export const connectToParent = (list) => { + let comments = [] + for(let item of list){ + comments.push({...item, child : []}); + } + + for(let comment1 of comments){ + if(comment1.pid !== null){ + const index = comments.indexOf(comments.filter((comment2) => comment2.id === comment1.pid)[0]); + comments[index] = {...comments[index], child : [comment1]}; + }else{ + console.log('nist :(') + } + } + console.log(comments); +} \ No newline at end of file