-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathComment.jsx
More file actions
65 lines (62 loc) · 1.95 KB
/
Comment.jsx
File metadata and controls
65 lines (62 loc) · 1.95 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import React, { Component } from "react";
import styles from "./Comment.css";
import ChangeCommentForm from "../ChangeCommentForm/ChangeCommentForm";
import PropTypes from "prop-types";
class Comment extends Component {
state = {
date: new Date(this.props.createDate).toLocaleDateString(),
isShowChangeForm: false,
};
onShowChangeForm = () => {
this.setState({
isShowChangeForm: !this.state.isShowChangeForm,
});
};
render() {
return (
<React.Fragment>
<div className={styles["comment-block"]}>
{this.state.isShowChangeForm && (
<ChangeCommentForm
comment={this.props}
onShowChangeForm={this.onShowChangeForm}
onEditComment={this.props.onEditComment}
/>
)}
<p className={styles["comment-text"]}>{this.props.text}</p>
<div className={styles["comment-data-block"]}>
<span className={styles["comment-data"]}>
Comment was written by {this.props.name}
</span>
<span className={styles["comment-data"]}>
Created: {this.state.date}
</span>
</div>
<div className={styles["comment-btns-block"]}>
<button
onClick={this.onShowChangeForm}
className={styles["comment-btn"]}
>
Edit comment
</button>
<button
onClick={() => this.props.onDeleteComment(this.props.createDate)}
className={styles["comment-btn"]}
>
Delete comment
</button>
</div>
</div>
</React.Fragment>
);
}
}
Comment.propTypes = {
createDate: PropTypes.func.isRequired,
name: PropTypes.string.isRequired,
onDeleteComment: PropTypes.func.isRequired,
onEditComment: PropTypes.func.isRequired,
text: PropTypes.string.isRequired,
createDate: PropTypes.shape().isRequired,
};
export default Comment;