react-code-dataset / wp-calypso /client /state /comments /selectors /get-post-comments-count-at-date.js
react-code-dataset / wp-calypso /client /state /comments /selectors /get-post-comments-count-at-date.js
Download wp-calypso/client/state/comments/selectors/get-post-comments-count-at-date.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/comments/selectors/get-post-comments-count-at-date.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/comments/selectors/get-post-comments-count-at-date.js
-
curl -L -o get-post-comments-count-at-date.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/comments/selectors/get-post-comments-count-at-date.js
1.04 kB
| import { getStateKey } from 'calypso/state/comments/utils'; | |
| import 'calypso/state/comments/init'; | |
| /** | |
| * Get total number of comments in state at a given date and time | |
| * @param {Object} state redux state | |
| * @param {number} siteId site identification | |
| * @param {number} postId site identification | |
| * @param {Date} date Date to count comments for | |
| * @returns {number} total comments count in state | |
| */ | |
| export function getPostCommentsCountAtDate( state, siteId, postId, date ) { | |
| // Check the provided date | |
| if ( ! ( date instanceof Date && ! isNaN( date ) ) ) { | |
| return 0; | |
| } | |
| const stateKey = getStateKey( siteId, postId ); | |
| const postComments = state.comments.items?.[ stateKey ]; | |
| if ( ! Array.isArray( postComments ) || ! postComments.length ) { | |
| return 0; | |
| } | |
| // Count post comments with the specified date | |
| const dateTimestamp = date.getTime() / 1000; | |
| const postCommentsAtDate = postComments.filter( ( postComment ) => { | |
| return Date.parse( postComment.date ) / 1000 === dateTimestamp; | |
| } ); | |
| return postCommentsAtDate.length; | |
| } | |