From e34f96832a6115c8238a8bb6f6418a60b1d821c6 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 21 Dec 2017 18:36:15 +0100 Subject: [PATCH] Refactor --- .../Moderation/components/ModerationQueue.js | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js b/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js index 72df10682..77851d568 100644 --- a/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js +++ b/client/coral-admin/src/routes/Moderation/components/ModerationQueue.js @@ -190,28 +190,22 @@ class ModerationQueue extends React.Component { componentDidUpdate (prev) { const {commentCount, selectedCommentId} = this.props; - // Switching to multi mode. - if (prev.singleView && !this.props.singleView) { + const switchedToMultiMode = prev.singleView && !this.props.singleView; + const switchedMode = prev.singleView !== this.props.singleView; + const selectedDifferentComment = prev.selectedCommentId !== selectedCommentId && selectedCommentId; + const moderatedLastComment = prev.comments.length > 0 && this.getCommentCountWithoutDagling() === 0; + + if (switchedToMultiMode) { // Reflow virtual list. this.reflowList(); } - if ( - - // Switching mode. - prev.singleView !== this.props.singleView || - - // Select different comment. - prev.selectedCommentId !== selectedCommentId && selectedCommentId - ) { + if (switchedMode || selectedDifferentComment) { this.scrollToSelectedComment(); } - // If the user just moderated the last (visible) comment - // AND there are more comments available on the server, - // go ahead and load more comments - if (prev.comments.length > 0 && this.getCommentCountWithoutDagling() === 0 && commentCount > 0) { + if (moderatedLastComment && commentCount > 0) { this.props.loadMore(); } }