diff --git a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js index 0fb315bffc7b..78becd360621 100644 --- a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js +++ b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js @@ -10,6 +10,8 @@ import Permissions from '../../Permissions'; import Timing from '../../actions/Timing'; import CONST from '../../../CONST'; import * as App from '../../actions/App'; +import * as Report from '../../actions/Report'; +import * as Session from '../../actions/Session'; // Screens import ReportScreen from '../../../pages/home/ReportScreen'; @@ -38,6 +40,9 @@ const propTypes = { }), ), + /** The report ID of the last opened public room as anonymous user */ + lastOpenedPublicRoomID: PropTypes.string, + isFirstTimeNewExpensifyUser: PropTypes.bool, route: PropTypes.shape({ @@ -54,6 +59,7 @@ const defaultProps = { betas: [], policies: {}, isFirstTimeNewExpensifyUser: false, + lastOpenedPublicRoomID: null, }; /** @@ -91,6 +97,15 @@ class MainDrawerNavigator extends Component { this.isFromCache = _.size(props.reports) > 0; } + componentDidMount() { + if (!this.props.lastOpenedPublicRoomID || Session.isAnonymousUser()) { + return; + } + // Re-open the last opened public room if the user logged in + Report.setLastOpenedPublicRoom(''); + Report.openReport(this.props.lastOpenedPublicRoomID); + } + shouldComponentUpdate(nextProps) { const initialNextParams = getInitialReportScreenParams( nextProps.reports, @@ -172,4 +187,7 @@ export default withOnyx({ isFirstTimeNewExpensifyUser: { key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, }, + lastOpenedPublicRoomID: { + key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, + }, })(MainDrawerNavigator); diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index df114df307f4..7d9c363273ef 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -40,7 +40,6 @@ import * as EmojiPickerAction from '../../libs/actions/EmojiPickerAction'; import TaskHeader from '../../components/TaskHeader'; import MoneyRequestHeader from '../../components/MoneyRequestHeader'; import * as ComposerActions from '../../libs/actions/Composer'; -import * as Session from '../../libs/actions/Session'; const propTypes = { /** Navigation route context info provided by react navigation */ @@ -84,9 +83,6 @@ const propTypes = { /** The account manager report ID */ accountManagerReportID: PropTypes.string, - /** The report ID of the last opened public room as anonymous user */ - lastOpenedPublicRoomID: PropTypes.string, - /** All of the personal details for everyone */ personalDetails: PropTypes.objectOf(personalDetailsPropType), @@ -107,7 +103,6 @@ const defaultProps = { policies: {}, accountManagerReportID: null, personalDetails: {}, - lastOpenedPublicRoomID: null, }; /** @@ -198,13 +193,6 @@ class ReportScreen extends React.Component { } fetchReportIfNeeded() { - // Re-open the last opened public room if the user logged in - if (this.props.lastOpenedPublicRoomID && !Session.isAnonymousUser()) { - Report.setLastOpenedPublicRoom(''); - Report.openReport(this.props.lastOpenedPublicRoomID); - return; - } - const reportIDFromPath = getReportID(this.props.route); // Report ID will be empty when the reports collection is empty. @@ -400,9 +388,6 @@ export default compose( withDrawerState, withNetwork(), withOnyx({ - lastOpenedPublicRoomID: { - key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, - }, isSidebarLoaded: { key: ONYXKEYS.IS_SIDEBAR_LOADED, },