UNPKG

@replyke/core

Version:

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

45 lines 1.92 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")); function useUpdateComment() { const axios = (0, useAxiosPrivate_1.default)(); const { projectId } = (0, useProject_1.default)(); const updateComment = (0, react_1.useCallback)(async ({ commentId, content, metadata }) => { if (!projectId) { throw new Error("No project specified"); } // At least one of content or metadata must be provided if (content === undefined && metadata === undefined) { throw new Error("Either content or metadata must be provided"); } // Validate content if provided if (content !== undefined && content.length < 1) { throw new Error("Comment is too short"); } // Validate metadata if provided if (metadata !== undefined && (typeof metadata !== "object" || metadata === null || Array.isArray(metadata))) { throw new Error("Metadata must be a valid object"); } // Build request body with only provided fields const requestBody = {}; if (content !== undefined) { requestBody.content = content; } if (metadata !== undefined) { requestBody.metadata = metadata; } const response = await axios.patch(`/${projectId}/comments/${commentId}`, requestBody); return response.data; }, [projectId, axios]); return updateComment; } exports.default = useUpdateComment; //# sourceMappingURL=useUpdateComment.js.map