Download wp-calypso/client/state/comments/selectors/get-comment-by-id.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 608 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/comments/selectors/get-comment-by-id.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/state/comments/selectors/get-comment-by-id.js
-
curl -L -o get-comment-by-id.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/state/comments/selectors/get-comment-by-id.js
608 Bytes
| import { filter, find, flatMap } from 'lodash'; | |
| import { deconstructStateKey, getErrorKey } from 'calypso/state/comments/utils'; | |
| import 'calypso/state/comments/init'; | |
| export function getCommentById( { state, commentId, siteId } ) { | |
| const errorKey = getErrorKey( siteId, commentId ); | |
| if ( state.comments.errors[ errorKey ] ) { | |
| return state.comments.errors[ errorKey ]; | |
| } | |
| const commentsForSite = flatMap( | |
| filter( state.comments.items, ( comment, key ) => { | |
| return deconstructStateKey( key ).siteId === siteId; | |
| } ) | |
| ); | |
| return find( commentsForSite, ( comment ) => commentId === comment.ID ); | |
| } | |