From 38c99371172df9e9b01e397b4e8c41d66191f21a Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Thu, 20 Jun 2019 12:18:55 +0300 Subject: [PATCH 1/3] Fixed profile page refreshing issue --- src/components/posts/view/postsView.js | 24 +++++++++++-------- .../profile/container/profileContainer.js | 20 ++++++++++------ src/screens/profile/screen/profileScreen.js | 4 ++++ 3 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index edb944429..a2b85f126 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -47,11 +47,12 @@ class PostsView extends Component { } componentWillReceiveProps(nextProps) { - const { currentAccountUsername } = this.props; + const { currentAccountUsername, changeForceLoadPostState } = this.props; if ( - currentAccountUsername !== nextProps.currentAccountUsername && - nextProps.currentAccountUsername + (currentAccountUsername !== nextProps.currentAccountUsername && + nextProps.currentAccountUsername) || + nextProps.forceLoadPost ) { // Set all initial data (New user new rules) this.setState( @@ -68,6 +69,9 @@ class PostsView extends Component { }, () => { this._loadPosts(); + if (changeForceLoadPostState) { + changeForceLoadPostState(false); + } }, ); } @@ -275,13 +279,13 @@ class PostsView extends Component { onScrollBeginDrag={() => this._handleOnScrollStart()} refreshControl={ + refreshing={refreshing} + onRefresh={this._handleOnRefreshPosts} + progressBackgroundColor="#357CE6" + tintColor={!isDarkTheme ? '#357ce6' : '#96c0ff'} + titleColor="#fff" + colors={['#fff']} + /> } ref={ref => { this.flatList = ref; diff --git a/src/screens/profile/container/profileContainer.js b/src/screens/profile/container/profileContainer.js index 1081f6d02..83796a939 100644 --- a/src/screens/profile/container/profileContainer.js +++ b/src/screens/profile/container/profileContainer.js @@ -44,6 +44,7 @@ class ProfileContainer extends Component { isReverseHeader, user: null, selectedQuickProfile: null, + forceLoadPost: false, }; } @@ -75,7 +76,7 @@ class ProfileContainer extends Component { }; componentWillReceiveProps(nextProps) { - const { navigation, currentAccount, activeBottomTab, isLoggedIn } = this.props; + const { activeBottomTab, currentAccount, isLoggedIn, navigation } = this.props; const currentUsername = currentAccount.name !== nextProps.currentAccount.name && nextProps.currentAccount.name; @@ -84,15 +85,13 @@ class ProfileContainer extends Component { return; } - if (currentUsername) { - this._loadProfile(currentUsername); - } - if ( - activeBottomTab !== nextProps.activeBottomTab && - nextProps.activeBottomTab === 'ProfileTabbar' + (activeBottomTab !== nextProps.activeBottomTab && + nextProps.activeBottomTab === ROUTES.TABBAR.PROFILE) || + currentUsername ) { this._loadProfile(currentAccount.name); + this.setState({ forceLoadPost: true }); } } @@ -334,6 +333,10 @@ class ProfileContainer extends Component { } }; + _changeForceLoadPostState = value => { + this.setState({ forceLoadPost: value }); + }; + render() { const { avatar, @@ -349,6 +352,7 @@ class ProfileContainer extends Component { selectedQuickProfile, user, username, + forceLoadPost, } = this.state; const { isDarkTheme, isLoggedIn, currency, navigation } = this.props; const activePage = (navigation.state.params && navigation.state.params.activePage) || 0; @@ -379,6 +383,8 @@ class ProfileContainer extends Component { selectedQuickProfile={selectedQuickProfile} selectedUser={user} username={username} + forceLoadPost={forceLoadPost} + changeForceLoadPostState={this._changeForceLoadPostState} /> ); } diff --git a/src/screens/profile/screen/profileScreen.js b/src/screens/profile/screen/profileScreen.js index ed52da15a..e5f6b9c7e 100644 --- a/src/screens/profile/screen/profileScreen.js +++ b/src/screens/profile/screen/profileScreen.js @@ -84,6 +84,8 @@ class ProfileScreen extends PureComponent { selectedUser, username, activePage, + forceLoadPost, + changeForceLoadPostState, } = this.props; const { @@ -206,6 +208,8 @@ class ProfileScreen extends PureComponent { tag={username} key={username} handleOnScroll={this._handleOnScroll} + forceLoadPost={forceLoadPost} + changeForceLoadPostState={changeForceLoadPostState} /> Date: Fri, 21 Jun 2019 11:24:41 +0300 Subject: [PATCH 2/3] Fixed comment requirements --- src/components/posts/view/postsView.js | 3 ++- src/screens/profile/container/profileContainer.js | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/components/posts/view/postsView.js b/src/components/posts/view/postsView.js index a2b85f126..7e9d80165 100644 --- a/src/components/posts/view/postsView.js +++ b/src/components/posts/view/postsView.js @@ -2,6 +2,7 @@ import React, { Component, Fragment } from 'react'; import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native'; import { injectIntl } from 'react-intl'; import { withNavigation } from 'react-navigation'; +import get from 'lodash/get'; // STEEM import { getPostsSummary } from '../../../providers/steem/dsteem'; @@ -28,7 +29,7 @@ class PostsView extends Component { isLoading: false, isPostsLoading: true, isHideImage: false, - selectedFilterIndex: props.selectedOptionIndex || 0, + selectedFilterIndex: get(props, 'selectedOptionIndex', 0), isNoPost: false, }; } diff --git a/src/screens/profile/container/profileContainer.js b/src/screens/profile/container/profileContainer.js index 83796a939..9fd27bd40 100644 --- a/src/screens/profile/container/profileContainer.js +++ b/src/screens/profile/container/profileContainer.js @@ -1,6 +1,7 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; import { withNavigation } from 'react-navigation'; +import get from 'lodash/get'; // Providers import { @@ -50,14 +51,14 @@ class ProfileContainer extends Component { componentDidMount = () => { const { navigation, isLoggedIn, currentAccount } = this.props; - const selectedUser = navigation.state && navigation.state.params; + const selectedUser = get(navigation.state, 'params'); if (!isLoggedIn && !selectedUser) { navigation.navigate(ROUTES.SCREENS.LOGIN); return; } - if (selectedUser && selectedUser.username && selectedUser.username !== currentAccount.name) { + if (get(selectedUser, 'username', false) && selectedUser.username !== currentAccount.name) { this._loadProfile(selectedUser.username); if (selectedUser.username) { @@ -326,9 +327,9 @@ class ProfileContainer extends Component { _handleOnBackPress = () => { const { navigation } = this.props; - const navigationParams = navigation.state && navigation.state.params; + const navigationParams = get(navigation.state, 'params'); - if (navigationParams && navigationParams.fetchData) { + if (get(navigationParams, 'fetchData')) { navigationParams.fetchData(); } }; @@ -355,11 +356,11 @@ class ProfileContainer extends Component { forceLoadPost, } = this.state; const { isDarkTheme, isLoggedIn, currency, navigation } = this.props; - const activePage = (navigation.state.params && navigation.state.params.activePage) || 0; + const activePage = get(navigation.state.params, 'state', 0); return ( Date: Sat, 22 Jun 2019 20:03:55 +0300 Subject: [PATCH 3/3] Comment requirements --- src/screens/profile/container/profileContainer.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/screens/profile/container/profileContainer.js b/src/screens/profile/container/profileContainer.js index 9fd27bd40..47c8277ea 100644 --- a/src/screens/profile/container/profileContainer.js +++ b/src/screens/profile/container/profileContainer.js @@ -79,7 +79,8 @@ class ProfileContainer extends Component { componentWillReceiveProps(nextProps) { const { activeBottomTab, currentAccount, isLoggedIn, navigation } = this.props; const currentUsername = - currentAccount.name !== nextProps.currentAccount.name && nextProps.currentAccount.name; + get(currentAccount, 'name') !== nextProps.currentAccount.name && + nextProps.currentAccount.name; if (isLoggedIn && !nextProps.isLoggedIn) { navigation.navigate(ROUTES.SCREENS.LOGIN); @@ -87,8 +88,8 @@ class ProfileContainer extends Component { } if ( - (activeBottomTab !== nextProps.activeBottomTab && - nextProps.activeBottomTab === ROUTES.TABBAR.PROFILE) || + (activeBottomTab !== get(nextProps, 'activeBottomTab') && + get(nextProps, 'activeBottomTab') === ROUTES.TABBAR.PROFILE) || currentUsername ) { this._loadProfile(currentAccount.name);