Skip to content

Commit 0798018

Browse files
committed
comments
1 parent ad16ef9 commit 0798018

File tree

7 files changed

+170
-47
lines changed

7 files changed

+170
-47
lines changed

package-lock.json

Lines changed: 54 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
"version": "0.1.0",
55
"private": true,
66
"dependencies": {
7-
"axios": "^0.18.0",
7+
"axios": "^0.19.0",
88
"bootstrap": "^4.3.1",
99
"dotenv": "^8.0.0",
1010
"http-proxy-middleware": "^0.19.1",
1111
"jquery": "^3.4.0",
12+
"local-storage": "^2.0.0",
1213
"material-ui": "^0.20.2",
1314
"moment": "^2.24.0",
1415
"popper.js": "^1.15.0",

src/components/comments.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import React, { Component } from "react";
2+
import Form from "react-bootstrap/Form";
3+
import Button from "react-bootstrap/Button";
4+
import { Card } from "react-bootstrap";
5+
6+
class Comments extends Component {
7+
constructor(props) {
8+
super(props);
9+
10+
this.state = { comments: [], pendingItem: "" };
11+
this.onChange = this.onChange.bind(this);
12+
this.onSubmit = this.onSubmit.bind(this);
13+
14+
console.log(this.state, "state");
15+
}
16+
17+
onChange(e) {
18+
e.preventDefault();
19+
console.log(e.target.value);
20+
21+
this.setState({ pendingItem: e.target.value });
22+
}
23+
24+
onSubmit(e) {
25+
e.preventDefault();
26+
this.setState({
27+
comments: [
28+
{
29+
comment: this.state.pendingItem
30+
},
31+
...this.state.comments
32+
],
33+
pendingItem: ""
34+
});
35+
}
36+
deleteComment(index) {
37+
const newComments = [...this.state.comments]
38+
newComments.splice(index, 1);
39+
this.setState({
40+
comments: newComments
41+
});
42+
}
43+
sortComment(){
44+
const sortedComments = [...this.state.comments]
45+
sortedComments.sort((a, b) => ( a.comment > b.comment ) ? 1 : -1)
46+
this.setState({
47+
comments: sortedComments
48+
})
49+
50+
}
51+
52+
render() {
53+
console.log(this.state.comments, "comments at render");
54+
return (
55+
<div>
56+
<Form onSubmit={this.onSubmit}>
57+
<Form.Control
58+
type="text"
59+
className="input"
60+
placeholder="Your Comments Here"
61+
value={this.state.pendingItem}
62+
onChange={this.onChange}
63+
/>
64+
65+
<Button variant="primary" type="submit">
66+
Add Your Comments
67+
</Button>
68+
69+
<Button variant="primary" onClick={()=> {
70+
this.sortComment()
71+
}}>
72+
Sort Comments
73+
</Button>
74+
75+
</Form>
76+
<div>
77+
{this.state.comments.map((comment, index) => {
78+
return (
79+
<Card
80+
key={index}
81+
style={{ background: "#31e8e8", opacity: "0.7" }}
82+
>
83+
{comment.comment}
84+
<Button
85+
onClick={() => {
86+
this.deleteComment(index);
87+
}}
88+
>
89+
DELETE
90+
</Button>
91+
</Card>
92+
);
93+
})}
94+
</div>
95+
</div>
96+
);
97+
}
98+
}
99+
100+
export default Comments;

src/components/employeesForm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ class EmployeeForm extends Component {
3232

3333
onSubmit(e) {
3434
e.preventDefault();
35-
35+
console.log('A');
3636
this.props.createEmployee(this.state);
37+
console.log('B');
3738
this.setState({
3839
employeename: "",
3940
user_id: "",

src/components/login.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { loginUser } from "../redux/actions/userActions";
66
import Button from "react-bootstrap/Button";
77
import Form from "react-bootstrap/Form";
88
import logo from "../images/logo.png";
9+
import Comments from "./comments"
910

1011
function validate(email, password) {
1112
// true means invalid, so our conditions got reversed
@@ -56,6 +57,8 @@ class Login extends Component {
5657
return !isDisabled;
5758
}
5859

60+
61+
5962
render() {
6063
console.log(this.state);
6164
const errors = validate(this.state.email, this.state.password);
@@ -132,6 +135,9 @@ class Login extends Component {
132135
</a>
133136
</div>
134137
</Form>
138+
139+
<Comments/>
140+
135141
</div>
136142
);
137143
}

src/containers/profileContainer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { Component } from "react";
2-
32
import BreakContainer from "../containers/breakContainer";
43
import CompanyContainer from "../containers/companyContainer";
54
import ManagerContainer from "../containers/managerContainer";

src/redux/actions/employeeActions.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export const fetchEmployees = () => {
2121
}
2222
}
2323
export const createEmployee = employee => {
24+
console.log('C');
2425
let data = {
2526
method: 'POST',
2627
headers: {
@@ -34,12 +35,15 @@ export const createEmployee = employee => {
3435
return dispatch => {
3536
fetch(`${ baseUrl }/employees`, data)
3637
.then(response => response.json())
37-
.then(employees => dispatch({
38+
.then(employees =>{
39+
console.log('D');
40+
dispatch({
3841
type: 'CREATE_EMPLOYEE',
3942
payload: employees
40-
}))
43+
})})
4144
.catch(err => err)
4245
}
46+
console.log('E');
4347
}
4448

4549
export const deleteEmployee = id => {

0 commit comments

Comments
 (0)