fix a race condition in handleScrollEvent (#85)
This commit is contained in:
+12
-16
@@ -369,23 +369,19 @@ class MessagesView extends React.Component {
|
|||||||
// Get older messages
|
// Get older messages
|
||||||
handleScrollEvent(event) {
|
handleScrollEvent(event) {
|
||||||
this.setState({scrollPosition: event.target.scrollHeight - event.target.scrollTop});
|
this.setState({scrollPosition: event.target.scrollHeight - event.target.scrollTop});
|
||||||
|
if (this.state.fetchingMessages) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (event.target.scrollTop <= 0) {
|
if (event.target.scrollTop <= 0) {
|
||||||
this.setState((prevState, props) => {
|
const topic = this.props.tinode.getTopic(this.state.topic);
|
||||||
const newState = {};
|
if (topic && topic.isSubscribed() && topic.msgHasMoreMessages()) {
|
||||||
if (!prevState.fetchingMessages) {
|
this.setState({fetchingMessages: true}, () => {
|
||||||
const topic = this.props.tinode.getTopic(this.state.topic);
|
topic.getMessagesPage(MESSAGES_PAGE)
|
||||||
if (topic && topic.isSubscribed() && topic.msgHasMoreMessages()) {
|
.catch((err) => this.props.onError(err.message, 'err'))
|
||||||
newState.fetchingMessages = true;
|
.finally(() => this.setState({fetchingMessages: false}));
|
||||||
topic.getMessagesPage(MESSAGES_PAGE)
|
});
|
||||||
.then(() => this.setState({fetchingMessages: false}))
|
}
|
||||||
.catch((err) => {
|
|
||||||
this.setState({fetchingMessages: false});
|
|
||||||
this.props.onError(err.message, 'err');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newState;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user