File size: 1,232 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
import { createSelector } from '@automattic/state-utils';
import { fetchStatusInitialState } from 'calypso/state/comments/reducer';
import { getPostCommentItems } from 'calypso/state/comments/selectors/get-post-comment-items';
import { getStateKey } from 'calypso/state/comments/utils';

import 'calypso/state/comments/init';

export const commentsFetchingStatus = createSelector(
	( state, siteId, postId, commentTotal = 0 ) => {
		const fetchStatus =
			state.comments.fetchStatus[ getStateKey( siteId, postId ) ] ?? fetchStatusInitialState;
		const hasMoreComments =
			commentTotal > ( getPostCommentItems( state, siteId, postId )?.length ?? 0 );

		return {
			haveEarlierCommentsToFetch: fetchStatus.before && hasMoreComments,
			haveLaterCommentsToFetch: fetchStatus.after && hasMoreComments,
			hasReceivedBefore: fetchStatus.hasReceivedBefore,
			hasReceivedAfter: fetchStatus.hasReceivedAfter,
		};
	},
	( state, siteId, postId, commentTotal = 0 ) => {
		const fetchStatus =
			state.comments.fetchStatus[ getStateKey( siteId, postId ) ] ?? fetchStatusInitialState;
		const hasMoreComments =
			commentTotal > ( getPostCommentItems( state, siteId, postId )?.length ?? 0 );
		return [ fetchStatus, hasMoreComments ];
	}
);