Added 'show comment' implementation for admins

This commit is contained in:
Simon Backx 2022-07-06 11:45:45 +02:00
parent 7570b2ef04
commit 121f1711cd
4 changed files with 42 additions and 6 deletions

View File

@ -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
};

View File

@ -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 (

View File

@ -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>
);
}
}

View File

@ -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>
);
}