@livelike/react-native
Version:
LiveLike React Native package
61 lines (60 loc) • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.useUserReactionActions = useUserReactionActions;
var _javascript = require("@livelike/javascript");
var _store = require("../store");
var _useAnalytics = require("./useAnalytics");
var _react = require("react");
function useUserReactionActions(_ref) {
let {
targetGroupId,
targetId
} = _ref;
const {
trackEvent
} = (0, _useAnalytics.useAnalytics)();
const removeReaction = (0, _react.useCallback)((actionArgs, selfReactionId) => {
_store.userReactionStoreActions.removeUserReactionAction(actionArgs);
(0, _javascript.removeUserReaction)({
reactionSpaceId: actionArgs.reactionSpaceId,
userReactionId: selfReactionId
}).then(res => {
trackEvent('Reaction Removed', {
targetGroupId,
reactionId: actionArgs.userReaction.reaction_id,
reactedById: actionArgs.profileId
});
return res;
}).catch(error => {
_store.userReactionStoreActions.addUserReactionAction(actionArgs);
(0, _javascript.hasDebugLogger)() && console.error(error);
return error;
});
}, [targetGroupId, targetId]);
const addReaction = (0, _react.useCallback)(actionArgs => {
_store.userReactionStoreActions.addUserReactionAction(actionArgs);
(0, _javascript.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 => {
_store.userReactionStoreActions.removeUserReactionAction(actionArgs);
(0, _javascript.hasDebugLogger)() && console.error(error);
return error;
});
}, [targetGroupId, targetId]);
return {
addReaction,
removeReaction
};
}
//# sourceMappingURL=useUserReactionActions.js.map