UNPKG

@replyke/core

Version:

Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.

45 lines 1.7 kB
"use strict"; 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")); const user_1 = require("../user"); // Hook for adding a comment function useCreateComment() { const axios = (0, useAxiosPrivate_1.default)(); const { projectId } = (0, useProject_1.default)(); const { user } = (0, user_1.useUser)(); const createComment = (0, react_1.useCallback)(async (props) => { const { entityId, foreignId, parentCommentId, content, gif, mentions, referencedCommentId, attachments, metadata, } = props; if (!projectId) { throw new Error("No project specified"); } if (!entityId) { throw new Error("No entity ID was provided"); } if (!user) { throw new Error("No authenticated user"); } if (!content && !gif) { throw new Error("No content was provided"); } const response = await axios.post(`/${projectId}/comments`, { entityId, foreignId, content, gif, mentions, parentId: parentCommentId, referencedCommentId, attachments, metadata, }); return response.data; }, [projectId, user, axios]); return createComment; } exports.default = useCreateComment; //# sourceMappingURL=useCreateComment.js.map