Skip to content

Commit 17995d6

Browse files
authored
Merge pull request #651 from humanmade/codex/fix-slack-marker-count
2 parents 4a7d9c8 + e5a69f8 commit 17995d6

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

‎src/components/Post/Summary.js‎

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Avatar from '../Avatar';
99
import Button from '../Button';
1010

1111
const _n = ( single, plural, count ) => count === 1 ? `1 ${ single }` : `${ count } ${ plural }`;
12+
const COMMENT_SUMMARY_LIMIT = 100;
1213

1314
const Person = props => {
1415
if ( ! props.user ) {
@@ -28,14 +29,47 @@ const Person = props => {
2829
const ConnectedPerson = withUser( props => props.id )( Person );
2930

3031
function Summary( props ) {
31-
const { comments, loadingComments, post, postVisible, onExpand } = props;
32+
const {
33+
comments,
34+
hasMoreComments,
35+
loadingComments,
36+
loadingMoreComments,
37+
onExpand,
38+
onLoadMoreComments,
39+
post,
40+
postVisible,
41+
} = props;
3242

3343
const continueReadingMessage = `Continue reading (${ _n( 'word', 'words', post.content.count ) })`;
3444

3545
// The archive is shared with the comment stream and so includes bot-authored
3646
// activity markers; exclude them from the count and avatar pile so they
3747
// never read as human comments.
38-
const realComments = comments ? comments.filter( comment => comment.type === 'comment' ) : [];
48+
const realComments = comments
49+
? comments.filter( comment => comment.type === 'comment' ).slice( 0, COMMENT_SUMMARY_LIMIT )
50+
: [];
51+
const hasActivityMarkers = comments ? comments.some( comment => comment.type !== 'comment' ) : false;
52+
53+
React.useEffect( () => {
54+
if (
55+
loadingComments
56+
|| loadingMoreComments
57+
|| ! hasMoreComments
58+
|| ! hasActivityMarkers
59+
|| realComments.length >= COMMENT_SUMMARY_LIMIT
60+
) {
61+
return;
62+
}
63+
64+
onLoadMoreComments( null );
65+
}, [
66+
hasActivityMarkers,
67+
hasMoreComments,
68+
loadingComments,
69+
loadingMoreComments,
70+
onLoadMoreComments,
71+
realComments.length,
72+
] );
3973

4074
const people = uniq( realComments.map( comment => comment.author ) ).filter( Boolean );
4175

@@ -103,15 +137,20 @@ export default withArchive(
103137
const archiveId = `stream:${ post.id }`;
104138
comments.registerArchive( archiveId, {
105139
post: post.id,
106-
per_page: 100,
140+
per_page: COMMENT_SUMMARY_LIMIT,
107141
slack_markers: 1,
108142
} );
109143
return archiveId;
110144
},
111145
{
112146
mapDataToProps: data => ( {
113147
comments: data.posts,
148+
hasMoreComments: data.hasMore,
114149
loadingComments: data.loading,
150+
loadingMoreComments: data.loadingMore,
151+
} ),
152+
mapActionsToProps: actions => ( {
153+
onLoadMoreComments: actions.onLoadMore,
115154
} ),
116155
}
117156
)( Summary );

0 commit comments

Comments
 (0)