File size: 1,455 Bytes
1e92f2d |
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 66 67 |
import { localize } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component, Fragment } from 'react';
import { connect } from 'react-redux';
import { Interval, EVERY_MINUTE } from 'calypso/lib/interval';
import { requestPostComments } from 'calypso/state/comments/actions';
import PostCommentsList from './post-comment-list';
class PostComments extends Component {
static propTypes = {
shouldHighlightNew: PropTypes.bool,
post: PropTypes.shape( {
ID: PropTypes.number.isRequired,
site_ID: PropTypes.number.isRequired,
} ).isRequired,
};
static defaultProps = {
shouldHighlightNew: false,
shouldPollForNewComments: false,
};
pollForNewComments = () => {
const { siteId, postId } = this.props;
// Request page of comments
this.props.requestPostComments( {
siteId,
postId,
isPoll: true,
direction: 'after',
} );
};
render() {
const { siteId, postId, shouldPollForNewComments } = this.props;
if ( ! siteId || ! postId ) {
return null;
}
return (
<Fragment>
{ shouldPollForNewComments && (
<Interval onTick={ this.pollForNewComments } period={ EVERY_MINUTE } />
) }
<PostCommentsList { ...this.props } />
</Fragment>
);
}
}
export default connect(
( state, ownProps ) => {
const siteId = ownProps.post.site_ID;
const postId = ownProps.post.ID;
return {
siteId,
postId,
};
},
{
requestPostComments,
}
)( localize( PostComments ) );
|