Merge pull request #914 from esteemapp/bugfix/profile-refresh

Fixed profile page refreshing issue
This commit is contained in:
uğur erdal 2019-06-24 11:14:56 +03:00 committed by GitHub
commit 7fbcd3a384
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 18 deletions

View File

@ -2,6 +2,7 @@ import React, { Component, Fragment } from 'react';
import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native'; import { FlatList, View, ActivityIndicator, RefreshControl } from 'react-native';
import { injectIntl } from 'react-intl'; import { injectIntl } from 'react-intl';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import get from 'lodash/get';
// STEEM // STEEM
import { getPostsSummary } from '../../../providers/steem/dsteem'; import { getPostsSummary } from '../../../providers/steem/dsteem';
@ -28,7 +29,7 @@ class PostsView extends Component {
isLoading: false, isLoading: false,
isPostsLoading: true, isPostsLoading: true,
isHideImage: false, isHideImage: false,
selectedFilterIndex: props.selectedOptionIndex || 0, selectedFilterIndex: get(props, 'selectedOptionIndex', 0),
isNoPost: false, isNoPost: false,
}; };
} }
@ -47,11 +48,12 @@ class PostsView extends Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { currentAccountUsername } = this.props; const { currentAccountUsername, changeForceLoadPostState } = this.props;
if ( if (
currentAccountUsername !== nextProps.currentAccountUsername && (currentAccountUsername !== nextProps.currentAccountUsername &&
nextProps.currentAccountUsername nextProps.currentAccountUsername) ||
nextProps.forceLoadPost
) { ) {
// Set all initial data (New user new rules) // Set all initial data (New user new rules)
this.setState( this.setState(
@ -68,6 +70,9 @@ class PostsView extends Component {
}, },
() => { () => {
this._loadPosts(); this._loadPosts();
if (changeForceLoadPostState) {
changeForceLoadPostState(false);
}
}, },
); );
} }

View File

@ -1,6 +1,7 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import get from 'lodash/get';
// Providers // Providers
import { import {
@ -44,19 +45,20 @@ class ProfileContainer extends Component {
isReverseHeader, isReverseHeader,
user: null, user: null,
selectedQuickProfile: null, selectedQuickProfile: null,
forceLoadPost: false,
}; };
} }
componentDidMount = () => { componentDidMount = () => {
const { navigation, isLoggedIn, currentAccount } = this.props; const { navigation, isLoggedIn, currentAccount } = this.props;
const selectedUser = navigation.state && navigation.state.params; const selectedUser = get(navigation.state, 'params');
if (!isLoggedIn && !selectedUser) { if (!isLoggedIn && !selectedUser) {
navigation.navigate(ROUTES.SCREENS.LOGIN); navigation.navigate(ROUTES.SCREENS.LOGIN);
return; return;
} }
if (selectedUser && selectedUser.username && selectedUser.username !== currentAccount.name) { if (get(selectedUser, 'username', false) && selectedUser.username !== currentAccount.name) {
this._loadProfile(selectedUser.username); this._loadProfile(selectedUser.username);
if (selectedUser.username) { if (selectedUser.username) {
@ -75,24 +77,23 @@ class ProfileContainer extends Component {
}; };
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
const { navigation, currentAccount, activeBottomTab, isLoggedIn } = this.props; const { activeBottomTab, currentAccount, isLoggedIn, navigation } = this.props;
const currentUsername = const currentUsername =
currentAccount.name !== nextProps.currentAccount.name && nextProps.currentAccount.name; get(currentAccount, 'name') !== nextProps.currentAccount.name &&
nextProps.currentAccount.name;
if (isLoggedIn && !nextProps.isLoggedIn) { if (isLoggedIn && !nextProps.isLoggedIn) {
navigation.navigate(ROUTES.SCREENS.LOGIN); navigation.navigate(ROUTES.SCREENS.LOGIN);
return; return;
} }
if (currentUsername) {
this._loadProfile(currentUsername);
}
if ( if (
activeBottomTab !== nextProps.activeBottomTab && (activeBottomTab !== get(nextProps, 'activeBottomTab') &&
nextProps.activeBottomTab === 'ProfileTabbar' get(nextProps, 'activeBottomTab') === ROUTES.TABBAR.PROFILE) ||
currentUsername
) { ) {
this._loadProfile(currentAccount.name); this._loadProfile(currentAccount.name);
this.setState({ forceLoadPost: true });
} }
} }
@ -327,13 +328,17 @@ class ProfileContainer extends Component {
_handleOnBackPress = () => { _handleOnBackPress = () => {
const { navigation } = this.props; 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(); navigationParams.fetchData();
} }
}; };
_changeForceLoadPostState = value => {
this.setState({ forceLoadPost: value });
};
render() { render() {
const { const {
avatar, avatar,
@ -349,13 +354,14 @@ class ProfileContainer extends Component {
selectedQuickProfile, selectedQuickProfile,
user, user,
username, username,
forceLoadPost,
} = this.state; } = this.state;
const { isDarkTheme, isLoggedIn, currency, navigation } = this.props; 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 ( return (
<ProfileScreen <ProfileScreen
about={user && user.about && user.about.profile} about={get(user, 'about.profile')}
activePage={activePage} activePage={activePage}
avatar={avatar} avatar={avatar}
comments={comments} comments={comments}
@ -379,6 +385,8 @@ class ProfileContainer extends Component {
selectedQuickProfile={selectedQuickProfile} selectedQuickProfile={selectedQuickProfile}
selectedUser={user} selectedUser={user}
username={username} username={username}
forceLoadPost={forceLoadPost}
changeForceLoadPostState={this._changeForceLoadPostState}
/> />
); );
} }

View File

@ -84,6 +84,8 @@ class ProfileScreen extends PureComponent {
selectedUser, selectedUser,
username, username,
activePage, activePage,
forceLoadPost,
changeForceLoadPostState,
} = this.props; } = this.props;
const { const {
@ -206,6 +208,8 @@ class ProfileScreen extends PureComponent {
tag={username} tag={username}
key={username} key={username}
handleOnScroll={this._handleOnScroll} handleOnScroll={this._handleOnScroll}
forceLoadPost={forceLoadPost}
changeForceLoadPostState={changeForceLoadPostState}
isHideReblogOption isHideReblogOption
/> />
</View> </View>