reza added utils

master
Reza_ashrafi 3 years ago
parent 37b6c90dca
commit 5fc14c682d
  1. 3
      src/components/Comments/index.js
  2. 11
      src/redux/data.js
  3. 16
      src/utils/comments.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 (
<div className="w-full flex flex-col">

@ -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: <Comments />,
code: null,
},
},
];
export default components;

@ -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);
}
Loading…
Cancel
Save