UNPKG

@replyke/core

Version:

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

40 lines 1.61 kB
import { useCallback } from "react"; import useAxiosPrivate from "../../config/useAxiosPrivate"; import useProject from "../projects/useProject"; function useUpdateComment() { const axios = useAxiosPrivate(); const { projectId } = useProject(); const updateComment = 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; } export default useUpdateComment; //# sourceMappingURL=useUpdateComment.js.map