From 3058202cb00b8eafdeebf5f0fc9967c70c5ecad1 Mon Sep 17 00:00:00 2001 From: Mustafa Buyukcelebi Date: Tue, 7 Jan 2020 15:46:26 +0300 Subject: [PATCH] Fixed account switch refresh issue --- .../sideMenu/container/sideMenuContainer.js | 3 ++- src/redux/actions/applicationActions.js | 6 ++++++ src/redux/constants/constants.js | 1 + src/redux/reducers/applicationReducer.js | 6 ++++++ .../application/container/applicationContainer.js | 11 +++++++++++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/sideMenu/container/sideMenuContainer.js b/src/components/sideMenu/container/sideMenuContainer.js index 8b2207f60..2295b95b9 100644 --- a/src/components/sideMenu/container/sideMenuContainer.js +++ b/src/components/sideMenu/container/sideMenuContainer.js @@ -6,7 +6,7 @@ import { getUserDataWithUsername } from '../../../realm/realm'; import { switchAccount } from '../../../providers/steem/auth'; import { updateCurrentAccount } from '../../../redux/actions/accountAction'; -import { logout } from '../../../redux/actions/applicationActions'; +import { logout, isRenderRequired } from '../../../redux/actions/applicationActions'; // Constanst import { default as ROUTES } from '../../../constants/routeNames'; @@ -73,6 +73,7 @@ class SideMenuContainer extends Component { _currentAccount.local = realmData[0]; dispatch(updateCurrentAccount(_currentAccount)); + dispatch(isRenderRequired(true)); navigation.closeDrawer(); }); } diff --git a/src/redux/actions/applicationActions.js b/src/redux/actions/applicationActions.js index 199a1ae01..0100d44eb 100644 --- a/src/redux/actions/applicationActions.js +++ b/src/redux/actions/applicationActions.js @@ -26,6 +26,7 @@ import { SET_UPVOTE_PERCENT, SET_PIN_CODE, IS_PIN_CODE_OPEN, + IS_RENDER_REQUIRED, } from '../constants/constants'; export const login = payload => ({ @@ -171,3 +172,8 @@ export const setPinCode = data => ({ type: SET_PIN_CODE, payload: data, }); + +export const isRenderRequired = payload => ({ + payload, + type: IS_RENDER_REQUIRED, +}); diff --git a/src/redux/constants/constants.js b/src/redux/constants/constants.js index d16eb656a..50f2d007e 100644 --- a/src/redux/constants/constants.js +++ b/src/redux/constants/constants.js @@ -13,6 +13,7 @@ export const IS_LOGGED_IN = 'IS_LOGGED_IN'; export const IS_LOGIN_DONE = 'IS_LOGIN_DONE'; export const IS_NOTIFICATION_OPEN = 'IS_NOTIFICATION_OPEN'; export const IS_DEFAULT_FOOTER = 'IS_DEFAULT_FOOTER'; +export const IS_RENDER_REQUIRED = 'IS_RENDER_REQUIRED'; export const LOGIN = 'LOGIN'; export const LOGOUT = 'LOGOUT'; export const LOGOUT_DONE = 'LOGOUT_DONE'; diff --git a/src/redux/reducers/applicationReducer.js b/src/redux/reducers/applicationReducer.js index f3842d09f..b08c65e77 100644 --- a/src/redux/reducers/applicationReducer.js +++ b/src/redux/reducers/applicationReducer.js @@ -24,6 +24,7 @@ import { SET_UPVOTE_PERCENT, SET_PIN_CODE, IS_PIN_CODE_OPEN, + IS_RENDER_REQUIRED, } from '../constants/constants'; const initialState = { @@ -57,6 +58,7 @@ const initialState = { nsfw: 'Always show', pin: null, isPinCodeOpen: true, + isRenderRequired: false, }; export default function(state = initialState, action) { @@ -198,6 +200,10 @@ export default function(state = initialState, action) { ...state, pin: action.payload, }; + case IS_RENDER_REQUIRED: + return Object.assign({}, state, { + isRenderRequired: action.payload, + }); default: return state; } diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index 5df23ab66..e38576df2 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -66,6 +66,7 @@ import { isDefaultFooter, isPinCodeOpen, setPinCode as savePinCode, + isRenderRequired, } from '../../../redux/actions/applicationActions'; import { updateActiveBottomTab } from '../../../redux/actions/uiAction'; @@ -120,6 +121,15 @@ class ApplicationContainer extends Component { if (!isIos) BackHandler.addEventListener('hardwareBackPress', this._onBackPress); }; + componentDidUpdate(prevProps, prevState) { + const { isGlobalRenderRequired, dispatch } = this.props; + + if (isGlobalRenderRequired !== prevProps.isGlobalRenderRequired && isGlobalRenderRequired) { + this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true })); + dispatch(isRenderRequired(false)); + } + } + componentWillUnmount() { const { isIos } = this.state; const { isPinCodeOpen: _isPinCodeOpen } = this.props; @@ -650,6 +660,7 @@ export default connect( isPinCodeRequire: state.application.isPinCodeRequire, isActiveApp: state.application.isActive, api: state.application.api, + isGlobalRenderRequired: state.application.isRenderRequired, // Account unreadActivityCount: state.account.currentAccount.unread_activity_count,