Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 27054 Conversations do not load if you interrupt the Internet connection when logging in #27380

Merged
merged 2 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ const ONYXKEYS = {
/** Is report data loading? */
IS_LOADING_REPORT_DATA: 'isLoadingReportData',

/** Is report data loading? */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's more than report data. And this comment looks copy-pasta

IS_LOADING_APP: 'isLoadingApp',

/** Is Keyboard shortcuts modal open? */
IS_SHORTCUTS_MODAL_OPEN: 'isShortcutsModalOpen',

Expand Down
17 changes: 16 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import DemoSetupPage from '../../../pages/DemoSetupPage';

let timezone;
let currentAccountID;
let isLoadingApp;

Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
Expand Down Expand Up @@ -75,6 +77,13 @@ Onyx.connect({
},
});

Onyx.connect({
key: ONYXKEYS.IS_LOADING_APP,
callback: (val) => {
isLoadingApp = val;
},
});

const RootStack = createCustomStackNavigator();

// We want to delay the re-rendering for components(e.g. ReportActionCompose)
Expand Down Expand Up @@ -126,7 +135,13 @@ class AuthScreens extends React.Component {

componentDidMount() {
NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => App.reconnectApp(this.props.lastUpdateIDAppliedToClient));
NetworkConnection.onReconnect(() => {
if (isLoadingApp) {
App.openApp();
} else {
App.reconnectApp(this.props.lastUpdateIDAppliedToClient);
}
});
PusherConnectionManager.init();
Pusher.init({
appKey: CONFIG.PUSHER.APP_KEY,
Expand Down
34 changes: 31 additions & 3 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,11 @@ function getPolicyParamsForOpenOrReconnect() {

/**
* Returns the Onyx data that is used for both the OpenApp and ReconnectApp API commands.
* @param {Boolean} isOpenApp
* @returns {Object}
*/
function getOnyxDataForOpenOrReconnect() {
return {
function getOnyxDataForOpenOrReconnect(isOpenApp = false) {
const defaultData = {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -167,14 +168,41 @@ function getOnyxDataForOpenOrReconnect() {
},
],
};
if (!isOpenApp) return defaultData;
return {
optimisticData: [
...defaultData.optimisticData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if it's a bad thing and haven't looked into the P/S - but got curious about why we need this. I see a lot of places in the app are "waiting" for the "is loading app" flag now and wonder if we need to do it in all those places or not...

"is loading app" sort of confuses me as a variable name. Maybe would have been better to call this: isLoadingCriticalAppData or something.

],
successData: [
...defaultData.successData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: false,
},
],
failureData: [
...defaultData.failureData,
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: false,
},
],
};
}

/**
* Fetches data needed for app initialization
*/
function openApp() {
getPolicyParamsForOpenOrReconnect().then((policyParams) => {
API.read('OpenApp', policyParams, getOnyxDataForOpenOrReconnect());
API.read('OpenApp', policyParams, getOnyxDataForOpenOrReconnect(true));
});
}

Expand Down
Loading