mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
Merge pull request #2207 from paulkaplan/show-replying-to
Show the username of the parent comment in replies
This commit is contained in:
commit
efc26aef21
2 changed files with 30 additions and 1 deletions
|
@ -5,6 +5,7 @@ const classNames = require('classnames');
|
||||||
|
|
||||||
const FlexRow = require('../../../components/flex-row/flex-row.jsx');
|
const FlexRow = require('../../../components/flex-row/flex-row.jsx');
|
||||||
const Avatar = require('../../../components/avatar/avatar.jsx');
|
const Avatar = require('../../../components/avatar/avatar.jsx');
|
||||||
|
const EmojiText = require('../../../components/emoji-text/emoji-text.jsx');
|
||||||
const FormattedRelative = require('react-intl').FormattedRelative;
|
const FormattedRelative = require('react-intl').FormattedRelative;
|
||||||
const FormattedMessage = require('react-intl').FormattedMessage;
|
const FormattedMessage = require('react-intl').FormattedMessage;
|
||||||
const ComposeComment = require('./compose-comment.jsx');
|
const ComposeComment = require('./compose-comment.jsx');
|
||||||
|
@ -93,6 +94,7 @@ class Comment extends React.Component {
|
||||||
datetimeCreated,
|
datetimeCreated,
|
||||||
id,
|
id,
|
||||||
projectId,
|
projectId,
|
||||||
|
replyUsername,
|
||||||
visibility
|
visibility
|
||||||
} = this.props;
|
} = this.props;
|
||||||
|
|
||||||
|
@ -160,7 +162,16 @@ class Comment extends React.Component {
|
||||||
* @user links in replies
|
* @user links in replies
|
||||||
* links to scratch.mit.edu pages
|
* links to scratch.mit.edu pages
|
||||||
*/}
|
*/}
|
||||||
<span className="comment-content">{content}</span>
|
|
||||||
|
<span className="comment-content">
|
||||||
|
{replyUsername && (
|
||||||
|
<a href={`/users/${replyUsername}`}>@{replyUsername} </a>
|
||||||
|
)}
|
||||||
|
<EmojiText
|
||||||
|
as="span"
|
||||||
|
text={content}
|
||||||
|
/>
|
||||||
|
</span>
|
||||||
<FlexRow className="comment-bottom-row">
|
<FlexRow className="comment-bottom-row">
|
||||||
<span className="comment-time">
|
<span className="comment-time">
|
||||||
<FormattedRelative value={new Date(datetimeCreated)} />
|
<FormattedRelative value={new Date(datetimeCreated)} />
|
||||||
|
@ -228,6 +239,7 @@ Comment.propTypes = {
|
||||||
onReport: PropTypes.func,
|
onReport: PropTypes.func,
|
||||||
onRestore: PropTypes.func,
|
onRestore: PropTypes.func,
|
||||||
projectId: PropTypes.string,
|
projectId: PropTypes.string,
|
||||||
|
replyUsername: PropTypes.string,
|
||||||
visibility: PropTypes.string
|
visibility: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@ class TopLevelComment extends React.Component {
|
||||||
this.state = {
|
this.state = {
|
||||||
expanded: false
|
expanded: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// A cache of {commentId: username, ...} in order to show reply usernames
|
||||||
|
this.commentUsernameCache = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleExpandThread () {
|
handleExpandThread () {
|
||||||
|
@ -50,6 +53,19 @@ class TopLevelComment extends React.Component {
|
||||||
this.props.onAddComment(comment, this.props.id);
|
this.props.onAddComment(comment, this.props.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
commentUsername (parentId) {
|
||||||
|
if (this.commentUsernameCache[parentId]) return this.commentUsernameCache[parentId];
|
||||||
|
|
||||||
|
// If the cache misses, rebuild it. Every reply has a parent id that is
|
||||||
|
// either a reply to this top level comment or to one of the replies.
|
||||||
|
this.commentUsernameCache[this.props.id] = this.props.author.username;
|
||||||
|
const replies = this.props.replies;
|
||||||
|
for (let i = 0; i < replies.length; i++) {
|
||||||
|
this.commentUsernameCache[replies[i].id] = replies[i].author.username;
|
||||||
|
}
|
||||||
|
return this.commentUsernameCache[parentId];
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const {
|
const {
|
||||||
author,
|
author,
|
||||||
|
@ -111,6 +127,7 @@ class TopLevelComment extends React.Component {
|
||||||
id={reply.id}
|
id={reply.id}
|
||||||
key={reply.id}
|
key={reply.id}
|
||||||
projectId={projectId}
|
projectId={projectId}
|
||||||
|
replyUsername={this.commentUsername(reply.parent_id)}
|
||||||
visibility={reply.visibility}
|
visibility={reply.visibility}
|
||||||
onAddComment={this.handleAddComment}
|
onAddComment={this.handleAddComment}
|
||||||
onDelete={this.handleDeleteReply}
|
onDelete={this.handleDeleteReply}
|
||||||
|
|
Loading…
Reference in a new issue