@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
33 lines • 1.4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
const useAxiosPrivate_1 = __importDefault(require("../../config/useAxiosPrivate"));
const useProject_1 = __importDefault(require("../projects/useProject"));
function useAddReaction() {
const axios = (0, useAxiosPrivate_1.default)();
const { projectId } = (0, useProject_1.default)();
const addReaction = (0, react_1.useCallback)(async (props) => {
const { targetType, targetId, reactionType } = props;
if (!targetId) {
throw new Error("No target ID provided");
}
if (!reactionType) {
throw new Error("No reaction type provided");
}
if (!projectId) {
throw new Error("No project specified");
}
// Determine endpoint based on targetType
const endpoint = targetType === "entity"
? `/${projectId}/entities/${targetId}/reactions`
: `/${projectId}/comments/${targetId}/reactions`;
const response = await axios.post(endpoint, { reactionType });
return response.data;
}, [axios, projectId]);
return addReaction;
}
exports.default = useAddReaction;
//# sourceMappingURL=useAddReaction.js.map