@replyke/core
Version:
Replyke: Build interactive apps with social features like comments, votes, feeds, user lists, notifications, and more.
47 lines • 1.72 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 useProject_1 = __importDefault(require("../projects/useProject"));
const useAxiosPrivate_1 = __importDefault(require("../../config/useAxiosPrivate"));
function useFetchManyComments() {
const { projectId } = (0, useProject_1.default)();
const axios = (0, useAxiosPrivate_1.default)();
const fetchComments = (0, react_1.useCallback)(async (props) => {
const { entityId, userId, parentId, sortBy, page, limit, include, sourceId, } = props;
if (page === 0) {
throw new Error("Can't fetch comments with page 0");
}
if (limit === 0) {
throw new Error("Can't fetch with limit 0");
}
if (!projectId) {
throw new Error("No project specified");
}
const params = {
sortBy,
page,
limit,
};
if (entityId)
params.entityId = entityId;
if (userId)
params.userId = userId;
if (parentId)
params.parentId = parentId;
if (sourceId)
params.sourceId = sourceId;
if (include) {
params.include = Array.isArray(include) ? include.join(',') : include;
}
const response = await axios.get(`/${projectId}/comments`, {
params,
});
return response.data;
}, [projectId, axios]);
return fetchComments;
}
exports.default = useFetchManyComments;
//# sourceMappingURL=useFetchManyComments.js.map