From 2d597e8402a76a51201b86756597db6f38fed5e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 30 May 2023 15:49:39 -0600 Subject: [PATCH 1/2] move lastOpenedPublicRoomID logic to main drawer --- .../AppNavigator/MainDrawerNavigator.js | 18 ++++++++++++++++++ src/pages/home/ReportScreen.js | 15 --------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js index 0fb315bffc7b..7b655eb8587a 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, }, From 3df36b8e15faad2c8cea5bb844f7d2cd5adcae40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 30 May 2023 17:30:32 -0600 Subject: [PATCH 2/2] fix lint error --- src/libs/Navigation/AppNavigator/MainDrawerNavigator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js index 7b655eb8587a..78becd360621 100644 --- a/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js +++ b/src/libs/Navigation/AppNavigator/MainDrawerNavigator.js @@ -99,7 +99,7 @@ class MainDrawerNavigator extends Component { componentDidMount() { if (!this.props.lastOpenedPublicRoomID || Session.isAnonymousUser()) { - return + return; } // Re-open the last opened public room if the user logged in Report.setLastOpenedPublicRoom('');