From a2c6040c79e5d619bea296f23fbde4dd20b87592 Mon Sep 17 00:00:00 2001 From: Narek Date: Sat, 16 Feb 2019 14:02:04 +0100 Subject: [PATCH 1/6] Add/Remove comment --- .../App/components/CustomComponents/Comp.js | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 client/modules/App/components/CustomComponents/Comp.js diff --git a/client/modules/App/components/CustomComponents/Comp.js b/client/modules/App/components/CustomComponents/Comp.js new file mode 100644 index 000000000..0ec6bab2f --- /dev/null +++ b/client/modules/App/components/CustomComponents/Comp.js @@ -0,0 +1,117 @@ +import React from 'react'; +import styles from './Comp.css' + +export class Comp extends React.Component{ + constructor(props){ + super(props); + this.state = { + arr : [{}], + click : false + } + this.addComment = this.addComment.bind(this); + } + + // Initialize main array to push state comments + arr = []; + + + addComment(index){ + + let userName = this.refs.userName.value; + let userTitle = this.refs.title.value; + let userPost = this.refs.post.value; + let form = document.getElementById('inputForm'); + let {arr} = this; + + if(userName.length > 0 && userTitle.length > 0 && userPost.length > 0){ + arr.push({ + name : userName, + title : userTitle, + post : userPost, + }) + this.setState({ + arr, + }) + } + + form.reset(); + } + + removeComment(index){ + const arr = this.arr; + arr.splice(index,1); + this.addState(); + } + + addState(){ + const {arr} = this; + this.setState({ + arr, + }) + } + + + + render(){ + const {arr} = this; + const {click} = this.state; + + return( +
+
+ + +