0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Wired up hiding comments admin API endpoint

no issue

The endpoint is not yet implemented on the backend, so it doesn't work yet.
This commit is contained in:
Simon Backx 2022-07-06 11:11:54 +02:00
parent 19ac2765e2
commit f711498a3e
3 changed files with 32 additions and 12 deletions

View file

@ -19,7 +19,7 @@ function AuthFrame({adminUrl, onLoad}) {
}; };
return ( return (
<iframe data-frame="admin-auth" src={adminUrl + 'auth-frame'} style={iframeStyle}></iframe> <iframe data-frame="admin-auth" src={adminUrl + 'auth-frame/'} style={iframeStyle}></iframe>
); );
} }
@ -117,7 +117,7 @@ export default class App extends React.Component {
action: `${action}:running` action: `${action}:running`
}); });
try { try {
const updatedState = await ActionHandler({action, data, state: this.state, api: this.GhostApi}); const updatedState = await ActionHandler({action, data, state: this.state, api: this.GhostApi, adminApi: this.adminApi});
this.setState(updatedState); this.setState(updatedState);
/** Reset action state after short timeout if not failed*/ /** Reset action state after short timeout if not failed*/
@ -129,6 +129,9 @@ export default class App extends React.Component {
}, 2000); }, 2000);
} }
} catch (error) { } catch (error) {
// todo: Keep this error log here until we implement popup notifications?
// eslint-disable-next-line no-console
console.error(error);
const popupNotification = createPopupNotification({ const popupNotification = createPopupNotification({
type: `${action}:failed`, type: `${action}:failed`,
autoHide: true, closeable: true, status: 'error', state: this.state, autoHide: true, closeable: true, status: 'error', state: this.state,
@ -224,11 +227,11 @@ export default class App extends React.Component {
const result = await callApi('getUser'); const result = await callApi('getUser');
return result.users[0]; return result.users[0];
}, },
hideComment(id) { async hideComment(id) {
return callApi('hideComment', {id}); return await callApi('hideComment', {id});
}, },
showComment(id) { async showComment(id) {
return callApi('showComment', {id}); return await callApi('showComment', {id});
} }
}; };

View file

@ -27,17 +27,34 @@ async function addComment({state, api, data: comment}) {
}; };
} }
async function hideComment({state, adminApi, data: comment}) {
await adminApi.hideComment(comment.id);
return {
comments: state.comments.map((c) => {
if (c.id === comment.id) {
return {
...c,
status: 'hidden'
};
}
return c;
})
};
}
const Actions = { const Actions = {
// Put your actions here // Put your actions here
addComment, addComment,
hideComment,
loadMoreComments loadMoreComments
}; };
/** Handle actions in the App, returns updated state */ /** Handle actions in the App, returns updated state */
export default async function ActionHandler({action, data, state, api}) { export default async function ActionHandler({action, data, state, api, adminApi}) {
const handler = Actions[action]; const handler = Actions[action];
if (handler) { if (handler) {
return await handler({data, state, api}) || {}; return await handler({data, state, api, adminApi}) || {};
} }
return {}; return {};
} }

View file

@ -8,16 +8,16 @@ class AdminContextMenu extends React.Component {
super(props); super(props);
this.state = {}; this.state = {};
this.deleteComment = this.deleteComment.bind(this); this.hideComment = this.hideComment.bind(this);
} }
deleteComment(event) { hideComment(event) {
// todo this.context.onAction('hideComment', this.props.comment);
} }
render() { render() {
return ( return (
<button onClick={this.deleteComment}> <button onClick={this.hideComment}>
Hide comment Hide comment
</button> </button>
); );