From 4a77531898465ca72811805975d9bddca7dc65c5 Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 13 Jun 2023 14:18:53 +0700 Subject: [PATCH 1/3] Fix app does not navigate to last opened public room in small screen devices after sign in --- .../Navigation/AppNavigator/AuthScreens.js | 12 ++++++++++++ .../AppNavigator/ReportScreenWrapper.js | 18 ------------------ src/libs/actions/Report.js | 13 +++++++++++++ 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 8539f384504c..7b57952c948d 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,8 @@ 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 +95,7 @@ const defaultProps = { session: { email: null, }, + lastOpenedPublicRoomID: null, }; class AuthScreens extends React.Component { @@ -115,6 +119,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.navigateToLastOpenedPublicRoom(this.props.lastOpenedPublicRoomID); + } Download.clearDownloads(); Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER); @@ -274,5 +283,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..0dabd6ddc966 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 navigateToLastOpenedPublicRoom(lastOpenedPublicRoomID) { + Navigation.isNavigationReady().then(() => { + setLastOpenedPublicRoom(''); + Navigation.navigate(ROUTES.getReportRoute(lastOpenedPublicRoomID)); + }); +} + /** * Flag a comment as offensive * @@ -1804,4 +1816,5 @@ export { leaveRoom, setLastOpenedPublicRoom, flagComment, + navigateToLastOpenedPublicRoom, }; From 81e16d1a6a99120d14514edebfacd63caac288c1 Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 13 Jun 2023 15:13:05 +0700 Subject: [PATCH 2/3] Fix eslint --- src/libs/actions/Report.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 0dabd6ddc966..98c9f4e2c7a1 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1682,7 +1682,7 @@ function setLastOpenedPublicRoom(reportID) { /** * Navigates to the last opened public room - * + * * @param {String} lastOpenedPublicRoomID */ function navigateToLastOpenedPublicRoom(lastOpenedPublicRoomID) { From 8b5881c0db88b156ce3e3d675e956397e28163de Mon Sep 17 00:00:00 2001 From: VH Date: Tue, 13 Jun 2023 17:48:42 +0700 Subject: [PATCH 3/3] Update method name --- src/libs/Navigation/AppNavigator/AuthScreens.js | 4 +++- src/libs/actions/Report.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 7b57952c948d..c4a84701a083 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -86,8 +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, }; @@ -122,7 +124,7 @@ class AuthScreens extends React.Component { if (this.props.lastOpenedPublicRoomID) { // Re-open the last opened public room if the user logged in from a public room link - Report.navigateToLastOpenedPublicRoom(this.props.lastOpenedPublicRoomID); + Report.openLastOpenedPublicRoom(this.props.lastOpenedPublicRoomID); } Download.clearDownloads(); Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER); diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 98c9f4e2c7a1..6a7f72055b54 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1685,7 +1685,7 @@ function setLastOpenedPublicRoom(reportID) { * * @param {String} lastOpenedPublicRoomID */ -function navigateToLastOpenedPublicRoom(lastOpenedPublicRoomID) { +function openLastOpenedPublicRoom(lastOpenedPublicRoomID) { Navigation.isNavigationReady().then(() => { setLastOpenedPublicRoom(''); Navigation.navigate(ROUTES.getReportRoute(lastOpenedPublicRoomID)); @@ -1816,5 +1816,5 @@ export { leaveRoom, setLastOpenedPublicRoom, flagComment, - navigateToLastOpenedPublicRoom, + openLastOpenedPublicRoom, };