Retrieving counts and displaying new comments to user.

This commit is contained in:
David Jay
2017-02-21 17:23:09 -05:00
parent 17813e23a9
commit 9149b737f5
10 changed files with 165 additions and 37 deletions
+21 -1
View File
@@ -17,10 +17,30 @@ class Stream extends React.Component {
constructor(props) {
super(props);
this.state = {activeReplyBox: ''};
this.state = {activeReplyBox: '', countPoll: null};
this.setActiveReplyBox = this.setActiveReplyBox.bind(this);
}
componentDidMount() {
const {asset, getCounts, updateCountCache} = this.props;
updateCountCache(asset.id, asset.comments.length);
// Note: Apollo's built-in polling doesn't work with fetchMore queries, so a
// setInterval is being used instead.
this.setState({
countPoll: setInterval(() => getCounts({
asset_id: asset.id,
limit: asset.comments.length,
sort: 'REVERSE_CHRONOLOGICAL'
}), 5000),
});
}
componentWillUnmount() {
clearInterval(this.state.countPoll);
}
setActiveReplyBox (reactKey) {
if (!this.props.currentUser) {
const offset = document.getElementById(`c_${reactKey}`).getBoundingClientRect().top - 75;