From 01ab4af1e2f1d8de547985d08defdbe524247547 Mon Sep 17 00:00:00 2001 From: enahum Date: Wed, 2 Aug 2017 09:37:50 -0400 Subject: [PATCH] Fix retry to get posts race condition (#809) --- .../channel_post_list/channel_post_list.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/screens/channel/channel_post_list/channel_post_list.js b/app/screens/channel/channel_post_list/channel_post_list.js index 108dd067f..4b2b09f5d 100644 --- a/app/screens/channel/channel_post_list/channel_post_list.js +++ b/app/screens/channel/channel_post_list/channel_post_list.js @@ -64,9 +64,7 @@ class ChannelPostList extends PureComponent { const {channel, posts, channelRefreshingFailed} = this.props; this.mounted = true; this.loadPosts(this.props.channel.id); - if (posts.length || channel.total_msg_count === 0 || channelRefreshingFailed) { - this.channelLoaded(); - } + this.shouldMarkChannelAsLoaded(posts.length, channel.total_msg_count === 0, channelRefreshingFailed); } componentWillReceiveProps(nextProps) { @@ -78,9 +76,7 @@ class ChannelPostList extends PureComponent { this.setState({ loaderOpacity: new Animated.Value(1) }, () => { - if (nextPosts.length || nextChannel.total_msg_count === 0 || nextChannelRefreshingFailed) { - this.channelLoaded(); - } + this.shouldMarkChannelAsLoaded(nextPosts.length, nextChannel.total_msg_count === 0, nextChannelRefreshingFailed); }); } @@ -95,6 +91,8 @@ class ChannelPostList extends PureComponent { this.toggleRetryMessage(false); } + this.shouldMarkChannelAsLoaded(nextPosts.length, nextChannel.total_msg_count === 0, nextChannelRefreshingFailed); + const showLoadMore = nextProps.posts.length >= nextProps.postVisibility; this.setState({ showLoadMore @@ -105,6 +103,12 @@ class ChannelPostList extends PureComponent { this.mounted = false; } + shouldMarkChannelAsLoaded = (postsCount, channelHasMessages, channelRefreshingFailed) => { + if (postsCount || channelHasMessages || channelRefreshingFailed) { + this.channelLoaded(); + } + }; + channelLoaded = () => { Animated.timing(this.state.loaderOpacity, { toValue: 0,