mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Added 'show comment' implementation for admins
This commit is contained in:
parent
7570b2ef04
commit
121f1711cd
@ -43,6 +43,22 @@ async function hideComment({state, adminApi, data: comment}) {
|
||||
};
|
||||
}
|
||||
|
||||
async function showComment({state, adminApi, data: comment}) {
|
||||
await adminApi.showComment(comment.id);
|
||||
|
||||
return {
|
||||
comments: state.comments.map((c) => {
|
||||
if (c.id === comment.id) {
|
||||
return {
|
||||
...c,
|
||||
status: 'published'
|
||||
};
|
||||
}
|
||||
return c;
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
async function deleteComment({state, api, data: comment}) {
|
||||
await api.comments.edit({
|
||||
comment: {
|
||||
@ -69,6 +85,7 @@ const Actions = {
|
||||
addComment,
|
||||
hideComment,
|
||||
deleteComment,
|
||||
showComment,
|
||||
loadMoreComments
|
||||
};
|
||||
|
||||
|
@ -29,7 +29,7 @@ class Comment extends React.Component {
|
||||
* (to hide the 'more' icon if we don't have any actions)
|
||||
*/
|
||||
get hasMoreContextMenu() {
|
||||
return !!this.context.member || !!this.context.admin;
|
||||
return (!!this.context.member && this.props.comment.status === 'published') || !!this.context.admin;
|
||||
}
|
||||
|
||||
render() {
|
||||
@ -37,7 +37,7 @@ class Comment extends React.Component {
|
||||
const html = {__html: comment.html};
|
||||
|
||||
if (comment.status !== 'published') {
|
||||
html.__html = '<i>This comment has been removed</i>';
|
||||
html.__html = '<i>This comment has been removed.</i>';
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -9,6 +9,7 @@ class AdminContextMenu extends React.Component {
|
||||
this.state = {};
|
||||
|
||||
this.hideComment = this.hideComment.bind(this);
|
||||
this.showComment = this.showComment.bind(this);
|
||||
}
|
||||
|
||||
hideComment(event) {
|
||||
@ -16,15 +17,33 @@ class AdminContextMenu extends React.Component {
|
||||
this.close();
|
||||
}
|
||||
|
||||
showComment(event) {
|
||||
this.context.onAction('showComment', this.props.comment);
|
||||
this.close();
|
||||
}
|
||||
|
||||
get isHidden() {
|
||||
return this.props.comment.status !== 'published';
|
||||
}
|
||||
|
||||
close() {
|
||||
this.props.close();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<button onClick={this.hideComment}>
|
||||
Hide comment
|
||||
</button>
|
||||
<div className="flex flex-col">
|
||||
{
|
||||
this.isHidden ?
|
||||
<button onClick={this.showComment}>
|
||||
Show comment
|
||||
</button>
|
||||
:
|
||||
<button onClick={this.hideComment}>
|
||||
Hide comment
|
||||
</button>
|
||||
}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class CommentContextMenu extends React.Component {
|
||||
|
||||
return (
|
||||
<div className="bg-white absolute font-sans rounded py-3 px-4 drop-shadow-xl text-sm whitespace-nowrap">
|
||||
{this.isAuthor ? <AuthorContextMenu comment={comment} close={this.close}/> : (this.isAdmin ? <AdminContextMenu comment={comment} close={this.close}/> : <NotAuthorContextMenu comment={comment} close={this.close}/>)}
|
||||
{this.isAuthor && comment.status === 'published' ? <AuthorContextMenu comment={comment} close={this.close}/> : (this.isAdmin ? <AdminContextMenu comment={comment} close={this.close}/> : <NotAuthorContextMenu comment={comment} close={this.close}/>)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user