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

Offline/Online toggle data fetch for WorkspacePageWithSections #8946

Merged
merged 1 commit into from
May 16, 2022
Merged
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
18 changes: 18 additions & 0 deletions src/pages/workspace/WorkspacePageWithSections.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ import reimbursementAccountPropTypes from '../ReimbursementAccount/reimbursement
import userPropTypes from '../settings/userPropTypes';
import KeyboardAvoidingView from '../../components/KeyboardAvoidingView';
import withFullPolicy from './withFullPolicy';
import {withNetwork} from '../../components/OnyxProvider';
import networkPropTypes from '../../components/networkPropTypes';

const propTypes = {
/** Information about the network from Onyx */
network: networkPropTypes.isRequired,

/** The text to display in the header */
headerText: PropTypes.string.isRequired,

Expand Down Expand Up @@ -65,6 +70,18 @@ const defaultProps = {

class WorkspacePageWithSections extends React.Component {
componentDidMount() {
this.fetchData();
}

componentDidUpdate(prevProps) {
if (!prevProps.network.isOffline || this.props.network.isOffline) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm confused...

If we were previously offline, and now we are no longer online, wouldn't we want to fetchData instead of return?

Copy link
Contributor Author

@PauloGasparSv PauloGasparSv May 14, 2022

Choose a reason for hiding this comment

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

It is a little confusing but I think it's correct!
It is saying "If we were prev online (!prevPros.network.isOffline) or if we are offline right now, then returns"
Which means, if we just got offline/disconnected from the web don't do anything
But if it doesn't enter that if statement, then it just came back online.

This if statement comes from the parent issue:
https://github.com/Expensify/Expensify/issues/208185

image

return;
}

this.fetchData();
}

fetchData() {
const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', '');
BankAccounts.fetchFreePlanVerifiedBankAccount('', achState);
}
Expand Down Expand Up @@ -118,4 +135,5 @@ export default compose(
},
}),
withFullPolicy,
withNetwork(),
)(WorkspacePageWithSections);