@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
40 lines • 1.38 kB
JavaScript
import { useCallback } from "react";
import useAxiosPrivate from "../../config/useAxiosPrivate";
import useProject from "../projects/useProject";
import { useUser } from "../user";
// Hook for adding a comment
function useCreateComment() {
const axios = useAxiosPrivate();
const { projectId } = useProject();
const { user } = useUser();
const createComment = 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;
}
export default useCreateComment;
//# sourceMappingURL=useCreateComment.js.map