0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00
ghost/apps/comments-ui/src/actions.js

37 lines
926 B
JavaScript
Raw Normal View History

2022-07-05 14:24:29 +02:00
function loadMoreComments({state, api}) {
let page = 1;
if (state.pagination && state.pagination.page) {
page = state.pagination.page + 1;
}
const data = api.comments.browse({page, postId: state.postId});
2022-07-05 14:24:29 +02:00
return {
comments: [...data.comments, ...state.comments],
pagination: data.meta.pagination
};
}
function addComment({state, api, data: comment}) {
const data = api.comments.add({comment});
return {
comments: [...data.comments, ...state.comments]
// todo: fix pagination now?
};
}
const Actions = {
// Put your actions here
addComment,
2022-07-05 14:24:29 +02:00
loadMoreComments
};
/** Handle actions in the App, returns updated state */
export default async function ActionHandler({action, data, state, api}) {
const handler = Actions[action];
if (handler) {
return await handler({data, state, api}) || {};
}
return {};
}