From 7493cda1a6a93e6a44b14c5669a1028685bf466f Mon Sep 17 00:00:00 2001 From: James Morris Date: Tue, 5 Jul 2022 16:16:48 +0100 Subject: [PATCH] Working avatars for comments but needs refactor --- apps/comments-ui/src/components/Comment.js | 82 ++++++++++------------ 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/apps/comments-ui/src/components/Comment.js b/apps/comments-ui/src/components/Comment.js index 335f279dde..6cc5b969ba 100644 --- a/apps/comments-ui/src/components/Comment.js +++ b/apps/comments-ui/src/components/Comment.js @@ -1,58 +1,48 @@ -import Avatar from './Avatar'; 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'; -class Comment extends React.Component { - static contextType = AppContext; +function Comment(props) { + const comment = props.comment; - constructor(props) { - super(props); - this.state = { - isContextMenuOpen: false - }; + const html = {__html: comment.html}; - this.toggleContextMenu = this.toggleContextMenu.bind(this); + function getInitials() { + if (!comment.member || !comment.member.name) { + return ''; + } + const parts = comment.member.name.split(' '); + + if (parts.length === 0) { + return ''; + } + + if (parts.length === 1) { + return parts[0].substring(0, 1); + } + + return parts[0].substring(0, 1) + parts[parts.length - 1].substring(0, 1); } - - toggleContextMenu() { - this.setState(state => ({ - isContextMenuOpen: !state.isContextMenuOpen - })); - } - - render() { - const comment = this.props.comment; - - const html = {__html: comment.html}; - - return ( -
-
-
- - -
-

{comment.member.name}

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

{ getInitials() }

- {/*
{comment.member.bio}
*/} - {/*
- {formatRelativeTime(comment.created_at)} -
*/} + Avatar +
+
+

{comment.member.name}

+
{formatRelativeTime(comment.created_at)}
-
-

-
- - {/*
button> - {this.state.isContextMenuOpen ? : null}*/} +
+
+

- ); - } +
+ ); } export default Comment;