diff --git a/apps/comments-ui/src/components/Comment.js b/apps/comments-ui/src/components/Comment.js index 71729c284e..7e0556a2a4 100644 --- a/apps/comments-ui/src/components/Comment.js +++ b/apps/comments-ui/src/components/Comment.js @@ -1,6 +1,5 @@ import {formatRelativeTime} from '../utils/helpers'; -import React from 'react'; -import AppContext from '../AppContext'; +import React, {useState} from 'react'; import Avatar from './Avatar'; import Like from './Like'; import Reply from './Reply'; @@ -8,74 +7,53 @@ import More from './More'; import EditForm from './EditForm'; import Replies from './Replies'; -class Comment extends React.Component { - static contextType = AppContext; +const Comment = (props) => { + const [isInEditMode, setIsInEditMode] = useState(false); - constructor(props) { - super(props); - this.state = { - isContextMenuOpen: false, - isInEditMode: false - }; + const toggleEditMode = () => { + setIsInEditMode(current => !current); + }; - this.toggleContextMenu = this.toggleContextMenu.bind(this); - this.toggleEditMode = this.toggleEditMode.bind(this); + const comment = props.comment; + const hasReplies = comment.replies && comment.replies.length > 0; + const html = {__html: comment.html}; + + if (comment.status !== 'published') { + html.__html = 'This comment has been removed.'; } - toggleContextMenu() { - this.setState(state => ({ - isContextMenuOpen: !state.isContextMenuOpen - })); + if (isInEditMode) { + return ( + + ); + } else { + return ( +
+
+
+ +
+

{comment.member.name}

+
{formatRelativeTime(comment.created_at)}
+
+
+
+

+
+
+ + + +
+
+ {hasReplies && +
+ +
+ } +
+ ); } - - toggleEditMode() { - this.setState(state => ({ - isInEditMode: !state.isInEditMode - })); - } - - render() { - const comment = this.props.comment; - const hasReplies = comment.replies && comment.replies.length > 0; - const html = {__html: comment.html}; - - if (comment.status !== 'published') { - html.__html = 'This comment has been removed.'; - } - - if (this.state.isInEditMode) { - return ( - - ); - } else { - return ( -
-
-
- -
-

{comment.member.name}

-
{formatRelativeTime(comment.created_at)}
-
-
-
-

-
-
- - - -
-
- {hasReplies && -
- -
- } -
- ); - } - } -} +}; export default Comment;