diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 8539f384504c..c4a84701a083 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -19,6 +19,7 @@ import KeyboardShortcut from '../../KeyboardShortcut'; import Navigation from '../Navigation'; import * as User from '../../actions/User'; import * as Modal from '../../actions/Modal'; +import * as Report from '../../actions/Report'; import modalCardStyleInterpolator from './modalCardStyleInterpolator'; import createResponsiveStackNavigator from './createResponsiveStackNavigator'; import SCREENS from '../../../SCREENS'; @@ -85,6 +86,10 @@ const propTypes = { session: PropTypes.shape({ email: PropTypes.string.isRequired, }), + + /** The report ID of the last opened public room as anonymous user */ + lastOpenedPublicRoomID: PropTypes.string, + ...windowDimensionsPropTypes, }; @@ -92,6 +97,7 @@ const defaultProps = { session: { email: null, }, + lastOpenedPublicRoomID: null, }; class AuthScreens extends React.Component { @@ -115,6 +121,11 @@ class AuthScreens extends React.Component { App.openApp(); App.setUpPoliciesAndNavigate(this.props.session); + + if (this.props.lastOpenedPublicRoomID) { + // Re-open the last opened public room if the user logged in from a public room link + Report.openLastOpenedPublicRoom(this.props.lastOpenedPublicRoomID); + } Download.clearDownloads(); Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER); @@ -274,5 +285,8 @@ export default compose( session: { key: ONYXKEYS.SESSION, }, + lastOpenedPublicRoomID: { + key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, + }, }), )(AuthScreens); diff --git a/src/libs/Navigation/AppNavigator/ReportScreenWrapper.js b/src/libs/Navigation/AppNavigator/ReportScreenWrapper.js index f8235a68745b..37ecc92a8f55 100644 --- a/src/libs/Navigation/AppNavigator/ReportScreenWrapper.js +++ b/src/libs/Navigation/AppNavigator/ReportScreenWrapper.js @@ -12,8 +12,6 @@ import reportPropTypes from '../../../pages/reportPropTypes'; import FullScreenLoadingIndicator from '../../../components/FullscreenLoadingIndicator'; import {withNavigationPropTypes} from '../../../components/withNavigation'; import * as App from '../../actions/App'; -import * as Report from '../../actions/Report'; -import * as Session from '../../actions/Session'; const propTypes = { /** Available reports that would be displayed in this navigator */ @@ -33,9 +31,6 @@ const propTypes = { }), ), - /** The report ID of the last opened public room as anonymous user */ - lastOpenedPublicRoomID: PropTypes.string, - isFirstTimeNewExpensifyUser: PropTypes.bool, /** Navigation route context info provided by react navigation */ @@ -58,7 +53,6 @@ const defaultProps = { betas: [], policies: {}, isFirstTimeNewExpensifyUser: false, - lastOpenedPublicRoomID: null, }; /** @@ -102,15 +96,6 @@ class ReportScreenWrapper extends Component { } } - 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) { // Don't update if there is a reportID in the params already if (lodashGet(this.props.route, 'params.reportID', null)) { @@ -161,7 +146,4 @@ export default withOnyx({ isFirstTimeNewExpensifyUser: { key: ONYXKEYS.NVP_IS_FIRST_TIME_NEW_EXPENSIFY_USER, }, - lastOpenedPublicRoomID: { - key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, - }, })(ReportScreenWrapper); diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 79e2ce35a1d9..6a7f72055b54 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1680,6 +1680,18 @@ function setLastOpenedPublicRoom(reportID) { Onyx.set(ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID, reportID); } +/** + * Navigates to the last opened public room + * + * @param {String} lastOpenedPublicRoomID + */ +function openLastOpenedPublicRoom(lastOpenedPublicRoomID) { + Navigation.isNavigationReady().then(() => { + setLastOpenedPublicRoom(''); + Navigation.navigate(ROUTES.getReportRoute(lastOpenedPublicRoomID)); + }); +} + /** * Flag a comment as offensive * @@ -1804,4 +1816,5 @@ export { leaveRoom, setLastOpenedPublicRoom, flagComment, + openLastOpenedPublicRoom, };