mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-17 00:21:20 -05:00
Make comment deleting and restoring correctly update replies
This commit is contained in:
parent
592c0e5703
commit
7772e197c7
3 changed files with 34 additions and 2 deletions
|
@ -123,6 +123,14 @@ module.exports.previewReducer = (state, action) => {
|
|||
comments: [action.comment, ...state.comments],
|
||||
replies: Object.assign({}, state.replies, {[action.comment.id]: []})
|
||||
});
|
||||
case 'UPDATE_ALL_REPLIES':
|
||||
return Object.assign({}, state, {
|
||||
replies: Object.assign({}, state.replies, {
|
||||
[action.commentId]: state.replies[action.commentId].map(reply =>
|
||||
Object.assign({}, reply, action.comment)
|
||||
)
|
||||
})
|
||||
});
|
||||
case 'SET_REPLIES':
|
||||
return Object.assign({}, state, {
|
||||
replies: merge({}, state.replies, action.replies)
|
||||
|
@ -237,6 +245,14 @@ module.exports.setCommentDeleted = (commentId, topLevelCommentId) => ({
|
|||
}
|
||||
});
|
||||
|
||||
module.exports.setRepliesDeleted = commentId => ({
|
||||
type: 'UPDATE_ALL_REPLIES',
|
||||
commentId: commentId,
|
||||
comment: {
|
||||
visibility: 'deleted'
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.setCommentReported = (commentId, topLevelCommentId) => ({
|
||||
type: 'UPDATE_COMMENT',
|
||||
commentId: commentId,
|
||||
|
@ -255,6 +271,14 @@ module.exports.setCommentRestored = (commentId, topLevelCommentId) => ({
|
|||
}
|
||||
});
|
||||
|
||||
module.exports.setRepliesRestored = commentId => ({
|
||||
type: 'UPDATE_ALL_REPLIES',
|
||||
commentId: commentId,
|
||||
comment: {
|
||||
visibility: 'visible'
|
||||
}
|
||||
});
|
||||
|
||||
module.exports.addNewComment = (comment, topLevelCommentId) => ({
|
||||
type: 'ADD_NEW_COMMENT',
|
||||
comment: comment,
|
||||
|
@ -648,6 +672,9 @@ module.exports.deleteComment = (projectId, commentId, topLevelCommentId, token)
|
|||
return;
|
||||
}
|
||||
dispatch(module.exports.setCommentDeleted(commentId, topLevelCommentId));
|
||||
if (!topLevelCommentId) {
|
||||
dispatch(module.exports.setRepliesDeleted(commentId));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -681,6 +708,9 @@ module.exports.restoreComment = (projectId, commentId, topLevelCommentId, token)
|
|||
return;
|
||||
}
|
||||
dispatch(module.exports.setCommentRestored(commentId, topLevelCommentId));
|
||||
if (!topLevelCommentId) {
|
||||
dispatch(module.exports.setRepliesRestored(commentId));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ class Comment extends React.Component {
|
|||
<span className="comment-time">
|
||||
<FormattedRelative value={new Date(datetimeCreated)} />
|
||||
</span>
|
||||
{canReply ? (
|
||||
{(canReply && visible) ? (
|
||||
<span
|
||||
className="comment-reply"
|
||||
onClick={this.handleToggleReplying}
|
||||
|
|
|
@ -66,6 +66,8 @@ class TopLevelComment extends React.Component {
|
|||
visibility
|
||||
} = this.props;
|
||||
|
||||
const canRestoreReplies = visibility === 'visible';
|
||||
|
||||
return (
|
||||
<FlexRow className="comment-container">
|
||||
<Comment
|
||||
|
@ -107,7 +109,7 @@ class TopLevelComment extends React.Component {
|
|||
onAddComment={this.handleAddComment}
|
||||
onDelete={this.handleDeleteReply}
|
||||
onReport={this.handleReportReply}
|
||||
onRestore={this.handleRestoreReply}
|
||||
onRestore={canRestoreReplies && this.handleRestoreReply}
|
||||
/>
|
||||
))}
|
||||
</FlexRow>
|
||||
|
|
Loading…
Reference in a new issue