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 1 commit
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
26 changes: 24 additions & 2 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,52 @@ function getPolicyParamsForOpenOrReconnect() {

/**
* Returns the Onyx data that is used for both the OpenApp and ReconnectApp API commands.
* @param {Boolean} isOpenApp
* @returns {Object}
*/
function getOnyxDataForOpenOrReconnect() {
function getOnyxDataForOpenOrReconnect(isOpenApp = false) {
return {
optimisticData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
value: true,
},
isOpenApp
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of making if else logic inside object - i will suggest to add one default one

const defaultData = {
    optimisticData: [
        {
            onyxMethod: 1,
            key: 2,
            value: true,
        },
    ],
    successData: [
        {
            onyxMethod: 3,
            key: 4,
            value: false,
        },
    ],
    failureData: [
        {
            onyxMethod: 5,
            key: 6,
            value: false,
        },
    ],
};

And add condition at line 148 if (!isOpenApp) return defaultData
And after it

return {
    ...defaultData,
    optimisticData: [...defaultData.optimisticData, {
        onyxMethod: 3,
        key: ONYXKEYS.IS_LOADING_APP,
        value: true,
    }],
    successData: [...defaultData.successData, {
        onyxMethod: 3,
        key: ONYXKEYS.IS_LOADING_APP,
        value: true,
    }],
    failureData: [...defaultData.failureData, {
        onyxMethod: 3,
        key: ONYXKEYS.IS_LOADING_APP,
        value: true,
    }]
}

? {
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: true,
}
: undefined,
],
successData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
value: false,
},
isOpenApp
? {
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: false,
}
: undefined,
],
failureData: [
{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
value: false,
},
isOpenApp
? {
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_APP,
value: false,
}
: undefined,
],
};
}
Expand All @@ -174,7 +196,7 @@ function getOnyxDataForOpenOrReconnect() {
*/
function openApp() {
getPolicyParamsForOpenOrReconnect().then((policyParams) => {
API.read('OpenApp', policyParams, getOnyxDataForOpenOrReconnect());
API.read('OpenApp', policyParams, getOnyxDataForOpenOrReconnect(true));
});
}

Expand Down