Prevent double execution of fetchMore

This commit is contained in:
Chi Vinh Le
2017-06-21 01:29:10 +07:00
parent 49420e152e
commit fc14e9d2fd
4 changed files with 51 additions and 14 deletions
@@ -53,6 +53,8 @@ function invalidateCursor(invalidated, state, props) {
class Stream extends React.Component {
isLoadingMoreMore = false;
constructor(props) {
super(props);
this.state = resetCursors(this.state, props);
@@ -95,6 +97,18 @@ class Stream extends React.Component {
}
};
loadMoreComments = () => {
if (!this.isLoadingMore) {
this.isLoadingMore = true;
this.props.loadMoreComments()
.then(() => this.isLoadingMore = false)
.catch((e) => {
this.isLoadingMore = false;
throw e;
});
}
}
// getVisibileComments returns a list containing comments
// which were authored by current user or comes after the `idCursor`.
getVisibleComments() {
@@ -288,7 +302,7 @@ class Stream extends React.Component {
<LoadMore
topLevel={true}
moreComments={asset.comments.hasNextPage}
loadMore={this.props.loadMoreComments}
loadMore={this.loadMoreComments}
/>
</div>}
</div>