File size: 712 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { getDocumentHeadUnreadCount } from 'calypso/state/document-head/selectors/get-document-head-unread-count';

const UNREAD_COUNT_CAP = 40;

/**
 * Returns a count reflecting unread items, capped at a value determined by
 * UNREAD_COUNT_CAP. Any value greater than the cap yields 'cap+'. Examples:
 * '1', '20', '39', '40+'
 * @param  {Object}  state  Global state tree
 * @returns {string}         Unread count (string because it can be e.g. '40+')
 */
export function getDocumentHeadCappedUnreadCount( state ) {
	const unreadCount = getDocumentHeadUnreadCount( state );
	if ( ! unreadCount ) {
		return '';
	}

	return unreadCount <= UNREAD_COUNT_CAP ? String( unreadCount ) : `${ UNREAD_COUNT_CAP }+`;
}