mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added basic context aware context menus
This commit is contained in:
parent
5479993c96
commit
172bbc07c6
5 changed files with 96 additions and 4 deletions
|
@ -2,8 +2,8 @@ import {formatRelativeTime} from '../utils/helpers';
|
|||
import {ReactComponent as MoreIcon} from '../images/icons/more.svg';
|
||||
import React from 'react';
|
||||
import AppContext from '../AppContext';
|
||||
import AuthorContextMenu from './modals/AuthorContextMenu';
|
||||
import {getInitials} from '../utils/helpers';
|
||||
import CommentContextMenu from './modals/CommentContextMenu';
|
||||
|
||||
class Comment extends React.Component {
|
||||
static contextType = AppContext;
|
||||
|
@ -52,7 +52,7 @@ class Comment extends React.Component {
|
|||
<p dangerouslySetInnerHTML={html} className="whitespace-pre-wrap"></p>
|
||||
</div>
|
||||
<button onClick={this.toggleContextMenu}><MoreIcon className='gh-comments-icon gh-comments-icon-more' /></button>
|
||||
{this.state.isContextMenuOpen ? <AuthorContextMenu /> : null}
|
||||
{this.state.isContextMenuOpen ? <CommentContextMenu comment={comment} /> : null}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
29
apps/comments-ui/src/components/modals/AdminContextMenu.js
Normal file
29
apps/comments-ui/src/components/modals/AdminContextMenu.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
import React from 'react';
|
||||
import AppContext from '../../AppContext';
|
||||
|
||||
class AdminContextMenu extends React.Component {
|
||||
static contextType = AppContext;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
|
||||
this.deleteComment = this.deleteComment.bind(this);
|
||||
}
|
||||
|
||||
deleteComment(event) {
|
||||
// todo
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className='bg-white absolute'>
|
||||
<button onClick={this.deleteComment}>
|
||||
Hide comment
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default AdminContextMenu;
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import AppContext from '../../AppContext';
|
||||
|
||||
class Form extends React.Component {
|
||||
class AuthorContextMenu extends React.Component {
|
||||
static contextType = AppContext;
|
||||
|
||||
constructor(props) {
|
||||
|
@ -29,4 +29,4 @@ class Form extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
export default Form;
|
||||
export default AuthorContextMenu;
|
||||
|
|
34
apps/comments-ui/src/components/modals/CommentContextMenu.js
Normal file
34
apps/comments-ui/src/components/modals/CommentContextMenu.js
Normal file
|
@ -0,0 +1,34 @@
|
|||
import React from 'react';
|
||||
import AppContext from '../../AppContext';
|
||||
import AdminContextMenu from './AdminContextMenu';
|
||||
import AuthorContextMenu from './AuthorContextMenu';
|
||||
import NotAuthorContextMenu from './NotAuthorContextMenu';
|
||||
|
||||
class CommentContextMenu extends React.Component {
|
||||
static contextType = AppContext;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
get isAuthor() {
|
||||
return this.props.comment.member.uuid === this.context?.member?.uuid;
|
||||
}
|
||||
|
||||
get isAdmin() {
|
||||
return false;
|
||||
}
|
||||
|
||||
render() {
|
||||
const comment = this.props.comment;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{this.isAuthor ? <AuthorContextMenu comment={comment}/> : (this.isAdmin ? <AdminContextMenu comment={comment}/> : <NotAuthorContextMenu comment={comment}/>)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default CommentContextMenu;
|
|
@ -0,0 +1,29 @@
|
|||
import React from 'react';
|
||||
import AppContext from '../../AppContext';
|
||||
|
||||
class NotAuthorContextMenu extends React.Component {
|
||||
static contextType = AppContext;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
|
||||
this.reportComment = this.reportComment.bind(this);
|
||||
}
|
||||
|
||||
reportComment(event) {
|
||||
// todo
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div className='bg-white absolute'>
|
||||
<button onClick={this.reportComment}>
|
||||
Report comment
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default NotAuthorContextMenu;
|
Loading…
Add table
Reference in a new issue