From 79f8a41b5baa1355cb1ca2e83f59b15ead56eebe Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 28 Aug 2019 21:01:35 -0700 Subject: [PATCH] fix: Loading state interrupts infinite scrolling --- app/components/PaginatedDocumentList.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/components/PaginatedDocumentList.js b/app/components/PaginatedDocumentList.js index 907e4e404..17cbe5878 100644 --- a/app/components/PaginatedDocumentList.js +++ b/app/components/PaginatedDocumentList.js @@ -21,6 +21,7 @@ type Props = { class PaginatedDocumentList extends React.Component { isInitiallyLoaded: boolean = false; @observable isLoaded: boolean = false; + @observable isFetchingMore: boolean = false; @observable isFetching: boolean = false; @observable offset: number = 0; @observable allowLoadMore: boolean = true; @@ -57,18 +58,22 @@ class PaginatedDocumentList extends React.Component { this.isLoaded = true; this.isFetching = false; + this.isFetchingMore = false; }; @action loadMoreResults = async () => { // Don't paginate if there aren't more results or we’re in the middle of fetching if (!this.allowLoadMore || this.isFetching) return; + + this.isFetchingMore = true; await this.fetchResults(); }; render() { const { empty, heading, documents, fetch, options, ...rest } = this.props; - const showLoading = this.isFetching && !this.isInitiallyLoaded; + const showLoading = + this.isFetching && !this.isFetchingMore && !this.isInitiallyLoaded; const showEmpty = !documents.length || showLoading; const showList = (this.isLoaded || this.isInitiallyLoaded) && !showLoading;