@@ -9,6 +9,7 @@ import Avatar from '../Avatar';
99import Button from '../Button' ;
1010
1111const _n = ( single , plural , count ) => count === 1 ? `1 ${ single } ` : `${ count } ${ plural } ` ;
12+ const COMMENT_SUMMARY_LIMIT = 100 ;
1213
1314const Person = props => {
1415 if ( ! props . user ) {
@@ -28,14 +29,47 @@ const Person = props => {
2829const ConnectedPerson = withUser ( props => props . id ) ( Person ) ;
2930
3031function 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