-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathPostCommentWidget.js
More file actions
48 lines (39 loc) · 1.48 KB
/
PostCommentWidget.js
File metadata and controls
48 lines (39 loc) · 1.48 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
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import styles from './PostCommentWidget.css';
import { FormattedMessage, injectIntl } from 'react-intl';
import { PostCreateWidget } from '../PostCreateWidget/PostCreateWidget';
export const isEmpty = obj => !Object.keys(obj).length;
export class PostCommentWidget extends PureComponent {
componentDidUpdate() {
const comment = this.props.edit;
if (!isEmpty(comment)) {
this.refs.name.value = comment.name;
this.refs.content.value = comment.content;
}
}
addComment = () => {
const nameRef = this.refs.name;
const contentRef = this.refs.content;
if (nameRef.value && contentRef.value) {
this.props.addComment(nameRef.value, contentRef.value, !isEmpty(this.props.edit));
nameRef.value = contentRef.value = '';
}
};
render() {
return (
<div>
<input placeholder={this.props.intl.messages.authorName} className={styles['form-field']} ref="name" />
<textarea placeholder={this.props.intl.messages.commentContent} className={styles['form-field']} ref="content" />
<a className={styles['post-submit-button']} href="#" onClick={this.addComment}><FormattedMessage id="submit" /></a>
</div>
);
}
}
PostCreateWidget.propTypes = {
addComment: PropTypes.func.isRequired,
edit: PropTypes.object,
// showAddPost: PropTypes.bool.isRequired,
// intl: intlShape.isRequired,
};
export default injectIntl(PostCommentWidget);