-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathPostComments.js
More file actions
45 lines (37 loc) · 1.35 KB
/
PostComments.js
File metadata and controls
45 lines (37 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import CommentForm from '../PostComments/formComponent/CommentForm';
import CommentsUser from './formComponent/CommentUser';
import styles from '../PostComments/PostComments.css';
import { addCommentRequestAPI } from '../../components/PostComments/CommentActions';
export class PostComments extends Component {
toAddCommentToStore = (author, text) => {
console.log(`${author} ${text}`);
const comment = { author, text };
console.log(comment);
comment.postCuid = this.props.post;
return this.props.dispatch(addCommentRequestAPI(comment));
}
render() {
const { comments } = this.props;
return (
<div className={`${styles['comments-list']}`}>
<CommentForm addComment={this.toAddCommentToStore} />
{
comments.length ?
comments.map((comment) => (<CommentsUser comment={comment} key={comment.cuid} />)) :
<span>PLease, leave your comment, be first !</span>
}
</div>
);
}
}
PostComments.propTypes = {
post: PropTypes.string.isRequired,
comments: PropTypes.array,
dispatch: PropTypes.func.isRequired,
};
export default connect(
(state, props) => ({ comments: state.comments.data.filter(comment => comment.postCuid === props.post) })
)(PostComments);