@livelike/react-native
Version:
LiveLike React Native package
55 lines • 1.81 kB
JavaScript
import { addUserReaction, hasDebugLogger, removeUserReaction } from '@livelike/javascript';
import { userReactionStoreActions } from '../store';
import { useAnalytics } from './useAnalytics';
import { useCallback } from 'react';
export function useUserReactionActions(_ref) {
let {
targetGroupId,
targetId
} = _ref;
const {
trackEvent
} = useAnalytics();
const removeReaction = useCallback((actionArgs, selfReactionId) => {
userReactionStoreActions.removeUserReactionAction(actionArgs);
removeUserReaction({
reactionSpaceId: actionArgs.reactionSpaceId,
userReactionId: selfReactionId
}).then(res => {
trackEvent('Reaction Removed', {
targetGroupId,
reactionId: actionArgs.userReaction.reaction_id,
reactedById: actionArgs.profileId
});
return res;
}).catch(error => {
userReactionStoreActions.addUserReactionAction(actionArgs);
hasDebugLogger() && console.error(error);
return error;
});
}, [targetGroupId, targetId]);
const addReaction = useCallback(actionArgs => {
userReactionStoreActions.addUserReactionAction(actionArgs);
addUserReaction({
reactionSpaceId: actionArgs.reactionSpaceId,
targetId,
reactionId: actionArgs.userReaction.reaction_id
}).then(res => {
trackEvent('Reaction Added', {
targetGroupId,
reactionId: actionArgs.userReaction.reaction_id,
reactedById: actionArgs.profileId
});
return res;
}).catch(error => {
userReactionStoreActions.removeUserReactionAction(actionArgs);
hasDebugLogger() && console.error(error);
return error;
});
}, [targetGroupId, targetId]);
return {
addReaction,
removeReaction
};
}
//# sourceMappingURL=useUserReactionActions.js.map