File size: 1,410 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import { POST_LIKERS_REQUEST, POST_LIKES_REQUEST } from 'calypso/state/action-types';
import { mergeHandlers } from 'calypso/state/action-watchers/utils';
import { registerHandlers } from 'calypso/state/data-layer/handler-registry';
import { http } from 'calypso/state/data-layer/wpcom-http/actions';
import { dispatchRequest } from 'calypso/state/data-layer/wpcom-http/utils';
import { receiveLikes, receivePostLikers } from 'calypso/state/posts/likes/actions';
import mine from './mine';
import newLike from './new';
export const fetch = ( action ) =>
http(
{
method: 'GET',
path: `/sites/${ action.siteId }/posts/${ action.postId }/likes`,
apiVersion: '1.1',
},
action
);
export const fromApi = ( data ) => ( {
found: +data.found,
iLike: !! data.i_like,
likes: data.likes,
} );
export const onLikersSuccess = ( { siteId, postId }, data ) =>
receivePostLikers( siteId, postId, data );
export const onLikesSuccess = ( { siteId, postId }, data ) => receiveLikes( siteId, postId, data );
registerHandlers(
'state/data-layer/wpcom/sites/posts/likes/index.js',
mergeHandlers( newLike, mine, {
[ POST_LIKERS_REQUEST ]: [
dispatchRequest( {
fetch,
fromApi,
onSuccess: onLikersSuccess,
onError: () => {},
} ),
],
[ POST_LIKES_REQUEST ]: [
dispatchRequest( {
fetch,
fromApi,
onSuccess: onLikesSuccess,
onError: () => {},
} ),
],
} )
);
|