react-code-dataset / wp-calypso /apps /notifications /src /panel /state /notes /thunks /set-like-status.js
react-code-dataset / wp-calypso /apps /notifications /src /panel /state /notes /thunks /set-like-status.js
Download wp-calypso/apps/notifications/src/panel/state/notes/thunks/set-like-status.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 995 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/notifications/src/panel/state/notes/thunks/set-like-status.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/apps/notifications/src/panel/state/notes/thunks/set-like-status.js
-
curl -L -o set-like-status.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/notifications/src/panel/state/notes/thunks/set-like-status.js
995 Bytes
| import { recordTracksEvent } from '../../../helpers/stats'; | |
| import { wpcom } from '../../../rest-client/wpcom'; | |
| import { likeNote } from '../actions'; | |
| import bumpStat from '../utils/bump-stat'; | |
| const setLikeStatus = | |
| ( noteId, siteId, postId, commentId, isLiked, restClient ) => async ( dispatch ) => { | |
| const type = commentId ? 'comment' : 'post'; | |
| dispatch( likeNote( noteId, isLiked ) ); | |
| bumpStat( `${ isLiked ? 'unlike' : 'like' }-${ type }` ); | |
| recordTracksEvent( 'calypso_notification_note_' + ( isLiked ? 'like' : 'unlike' ), { | |
| note_type: type, | |
| } ); | |
| const entityPath = type === 'comment' ? `comments/${ commentId }` : `posts/${ postId }`; | |
| if ( isLiked ) { | |
| await wpcom().req.post( `/sites/${ siteId }/${ entityPath }/likes/new` ); | |
| } else { | |
| await wpcom().req.del( `/sites/${ siteId }/${ entityPath }/likes/mine/delete` ); | |
| } | |
| // getNote() updates the redux store with a fresh object from the API | |
| restClient.getNote( noteId ); | |
| }; | |
| export default setLikeStatus; | |