mirror of
https://github.com/wassname/talk.git
synced 2026-07-21 12:51:03 +08:00
Refactor
This commit is contained in:
@@ -195,22 +195,17 @@ class ModerationQueue extends React.Component {
|
||||
|
||||
// Reflow virtual list.
|
||||
this.reflowList();
|
||||
|
||||
// Scroll to selected comment.
|
||||
if (this.props.selectedCommentId) {
|
||||
const view = this.state.view;
|
||||
const index = view.findIndex(({id}) => id === selectedCommentId);
|
||||
this.listRef.scrollToRow(index);
|
||||
}
|
||||
}
|
||||
|
||||
// Switching to single mode.
|
||||
if (!prev.singleView && this.props.singleView) {
|
||||
if (
|
||||
|
||||
// Scroll to comment.
|
||||
if (this.props.selectedCommentId) {
|
||||
document.querySelector(`#comment_${this.props.selectedCommentId}`).scrollIntoView();
|
||||
}
|
||||
// Switching mode.
|
||||
prev.singleView !== this.props.singleView ||
|
||||
|
||||
// Select different comment.
|
||||
prev.selectedCommentId !== selectedCommentId && selectedCommentId
|
||||
) {
|
||||
this.scrollToSelectedComment();
|
||||
}
|
||||
|
||||
// If the user just moderated the last (visible) comment
|
||||
@@ -219,15 +214,6 @@ class ModerationQueue extends React.Component {
|
||||
if (prev.comments.length > 0 && this.getCommentCountWithoutDagling() === 0 && commentCount > 0) {
|
||||
this.props.loadMore();
|
||||
}
|
||||
|
||||
// Scroll to new selected comment.
|
||||
if (prev.selectedCommentId !== selectedCommentId && this.listRef) {
|
||||
|
||||
const view = this.state.view;
|
||||
const index = view.findIndex(({id}) => id === selectedCommentId);
|
||||
|
||||
this.listRef.scrollToRow(index);
|
||||
}
|
||||
}
|
||||
|
||||
// Returns comment counts without dangling comments.
|
||||
@@ -265,6 +251,17 @@ class ModerationQueue extends React.Component {
|
||||
this.listRef = list;
|
||||
};
|
||||
|
||||
scrollToSelectedComment = (props = this.props, state = this.state) => {
|
||||
if (props.singleMode) {
|
||||
document.querySelector(`#comment_${props.selectedCommentId}`).scrollIntoView();
|
||||
}
|
||||
else if(this.listRef) {
|
||||
const view = state.view;
|
||||
const index = view.findIndex(({id}) => id === props.selectedCommentId);
|
||||
this.listRef.scrollToRow(index);
|
||||
}
|
||||
}
|
||||
|
||||
viewNewComments = (callback) => {
|
||||
this.setState(resetCursors, () => {
|
||||
this.reflowList();
|
||||
|
||||
Reference in New Issue
Block a user