Live update replies on all sort and always refetch

This commit is contained in:
Chi Vinh Le
2017-08-30 00:27:14 +07:00
parent 393005fce6
commit 21e4cf5865
@@ -84,6 +84,10 @@ class StreamContainer extends React.Component {
return prev;
}
// Newest top-level comments are only added when sorting by 'newest first'.
if (!commentAdded.parent && !this.isSortedByNewestFirst()) {
return prev;
}
return insertCommentIntoEmbedQuery(prev, commentAdded);
},
});
@@ -163,32 +167,9 @@ class StreamContainer extends React.Component {
}
componentWillReceiveProps(nextProps) {
const prevSortedNewest = this.isSortedByNewestFirst(this.props);
const nextSortedNewest = this.isSortedByNewestFirst(nextProps);
// When switching to 'Newest first' we refetch and subscribe so that
// we always have the newest comments.
if (!prevSortedNewest && nextSortedNewest) {
if (this.props.sortOrder !== nextProps.sortOrder || this.props.sortBy !== nextProps.sortBy) {
nextProps.data.refetch();
this.subscribeToCommentsAdded();
}
// When switching away from 'Newest first' unsubscribe from newest comments.
if (prevSortedNewest && !nextSortedNewest) {
this.unsubscribeCommentsAdded();
}
}
shouldComponentUpdate(nextProps) {
const prevSortedNewest = this.isSortedByNewestFirst(this.props);
const nextSortedNewest = this.isSortedByNewestFirst(nextProps);
if (!prevSortedNewest && nextSortedNewest) {
// When switching to 'Newest first' we refetch => skip
// rendering this frame and wait for refetch to kick in.
return false;
}
return true;
}
userIsDegraged({auth: {user}} = this.props) {