fix message scrolling on initial load

This commit is contained in:
or-else
2021-08-23 16:54:52 -07:00
parent f3e54e46b5
commit 763a525292
5 changed files with 15 additions and 15 deletions
+7 -7
View File
@@ -124,7 +124,7 @@ class MessagesView extends React.Component {
// or vertical shrinking. // or vertical shrinking.
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (this.messagesScroller) { if (this.messagesScroller) {
if (prevState.topic != this.state.topic || prevState.latestMsgSeq != this.state.latestMsgSeq) { if (prevState.topic != this.state.topic || prevState.messageCount != this.state.messageCount) {
// New message // New message
this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition; this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition;
} else if (prevProps.viewportHeight > this.props.viewportHeight) { } else if (prevProps.viewportHeight > this.props.viewportHeight) {
@@ -208,7 +208,7 @@ class MessagesView extends React.Component {
if (!nextProps.topic) { if (!nextProps.topic) {
// Default state: no topic. // Default state: no topic.
nextState = { nextState = {
latestMsgSeq: -1, messageCount: 0,
latestClearId: -1, latestClearId: -1,
onlineSubs: [], onlineSubs: [],
topic: null, topic: null,
@@ -274,14 +274,14 @@ class MessagesView extends React.Component {
}); });
} }
Object.assign(nextState, { Object.assign(nextState, {
latestMsgSeq: topic.maxMsgSeq(), messageCount: topic.messageCount(),
latestClearId: topic.maxClearId(), latestClearId: topic.maxClearId(),
channel: topic.isChannelType() channel: topic.isChannelType()
}); });
} else { } else {
// Invalid topic. // Invalid topic.
Object.assign(nextState, { Object.assign(nextState, {
latestMsgSeq: -1, messageCount: 0,
latestClearId: -1, latestClearId: -1,
onlineSubs: [], onlineSubs: [],
title: '', title: '',
@@ -500,10 +500,10 @@ class MessagesView extends React.Component {
return; return;
} }
this.setState({latestMsgSeq: topic.maxMsgSeq()}); this.setState({messageCount: topic.messageCount()});
// If the message is added to the end of the message list, // Scroll to the bottom if the message is added to the end of the message list.
// scroll to the bottom. // TODO: This should be replaced by showing a "scroll to bottom" button.
if (topic.isNewMessage(msg.seq)) { if (topic.isNewMessage(msg.seq)) {
this.setState({scrollPosition: 0}); this.setState({scrollPosition: 0});
} }
+5 -5
View File
@@ -3188,7 +3188,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
componentDidUpdate(prevProps, prevState) { componentDidUpdate(prevProps, prevState) {
if (this.messagesScroller) { if (this.messagesScroller) {
if (prevState.topic != this.state.topic || prevState.latestMsgSeq != this.state.latestMsgSeq) { if (prevState.topic != this.state.topic || prevState.messageCount != this.state.messageCount) {
this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition; this.messagesScroller.scrollTop = this.messagesScroller.scrollHeight - this.state.scrollPosition;
} else if (prevProps.viewportHeight > this.props.viewportHeight) { } else if (prevProps.viewportHeight > this.props.viewportHeight) {
this.messagesScroller.scrollTop += prevProps.viewportHeight - this.props.viewportHeight; this.messagesScroller.scrollTop += prevProps.viewportHeight - this.props.viewportHeight;
@@ -3268,7 +3268,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
if (!nextProps.topic) { if (!nextProps.topic) {
nextState = { nextState = {
latestMsgSeq: -1, messageCount: 0,
latestClearId: -1, latestClearId: -1,
onlineSubs: [], onlineSubs: [],
topic: null, topic: null,
@@ -3335,13 +3335,13 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
} }
Object.assign(nextState, { Object.assign(nextState, {
latestMsgSeq: topic.maxMsgSeq(), messageCount: topic.messageCount(),
latestClearId: topic.maxClearId(), latestClearId: topic.maxClearId(),
channel: topic.isChannelType() channel: topic.isChannelType()
}); });
} else { } else {
Object.assign(nextState, { Object.assign(nextState, {
latestMsgSeq: -1, messageCount: 0,
latestClearId: -1, latestClearId: -1,
onlineSubs: [], onlineSubs: [],
title: '', title: '',
@@ -3573,7 +3573,7 @@ class MessagesView extends (react__WEBPACK_IMPORTED_MODULE_0___default().Compone
} }
this.setState({ this.setState({
latestMsgSeq: topic.maxMsgSeq() messageCount: topic.messageCount()
}); });
if (topic.isNewMessage(msg.seq)) { if (topic.isNewMessage(msg.seq)) {
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long