forked from shakacode/react-webpack-rails-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommentBox.jsx
58 lines (52 loc) · 1.72 KB
/
CommentBox.jsx
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
import React, { PropTypes } from 'react';
import CommentForm from './CommentForm/CommentForm';
import CommentList from './CommentList/CommentList';
import css from './CommentBox.scss';
import BaseComponent from 'libs/components/BaseComponent';
export default class CommentBox extends BaseComponent {
static propTypes = {
pollInterval: PropTypes.number.isRequired,
actions: PropTypes.object.isRequired,
data: PropTypes.object.isRequired,
};
componentDidMount() {
const { fetchComments } = this.props.actions;
fetchComments();
this.intervalId = setInterval(fetchComments, this.props.pollInterval);
}
componentWillUnmount() {
clearInterval(this.intervalId);
}
render() {
const { actions, data } = this.props;
const cssTransitionGroupClassNames = {
enter: css.elementEnter,
enterActive: css.elementEnterActive,
leave: css.elementLeave,
leaveActive: css.elementLeaveActive,
};
return (
<div className="commentBox container">
<h2>
Comments {data.get('isFetching') && 'Loading...'}
</h2>
<p>
<b>Text</b> supports Github Flavored Markdown.
Comments older than 24 hours are deleted.<br />
<b>Name</b> is preserved. <b>Text</b> is reset, between submits.
</p>
<CommentForm
isSaving={data.get('isSaving')}
error={data.get('submitCommentError')}
actions={actions}
cssTransitionGroupClassNames={cssTransitionGroupClassNames}
/>
<CommentList
$$comments={data.get('$$comments')}
error={data.get('fetchCommentError')}
cssTransitionGroupClassNames={cssTransitionGroupClassNames}
/>
</div>
);
}
}