Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yuwenmemon committed Aug 3, 2022
1 parent 4e3a4d2 commit f72ce58
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 21 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ That action will then call `Onyx.merge()` to [set default data and a loading sta

```js
function signIn(password, twoFactorAuthCode) {
Onyx.merge(ONYXKEYS.ACCOUNT, {loading: true});
Onyx.merge(ONYXKEYS.ACCOUNT, {isLoading: true});
Authentication.Authenticate({
...defaultParams,
password,
Expand All @@ -177,7 +177,7 @@ function signIn(password, twoFactorAuthCode) {
Onyx.merge(ONYXKEYS.ACCOUNT, {error: error.message});
})
.finally(() => {
Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false});
Onyx.merge(ONYXKEYS.ACCOUNT, {isLoading: false});
});
}
```
Expand All @@ -188,7 +188,7 @@ Keeping our `Onyx.merge()` out of the view layer and in actions helps organize t
// Bad
validateAndSubmitForm() {
// validate...
this.setState({loading: true});
this.setState({isLoading: true});
signIn()
.then((response) => {
if (result.jsonCode === 200) {
Expand All @@ -198,7 +198,7 @@ validateAndSubmitForm() {
this.setState({error: response.message});
})
.finally(() => {
this.setState({loading: false});
this.setState({isLoading: false});
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function resendValidationLink(login = credentials.login) {
*
* @param {String} login
*/
function fetchAccountDetails(login) {
function beginSignIn(login) {
const optimisticData = [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
Expand Down Expand Up @@ -492,7 +492,7 @@ function setShouldShowComposeInput(shouldShowComposeInput) {
}

export {
fetchAccountDetails,
beginSignIn,
setPassword,
signIn,
signInWithShortLivedToken,
Expand Down
14 changes: 7 additions & 7 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ function updatePassword(oldPassword, password) {
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {...CONST.DEFAULT_ACCOUNT_DATA, loading: true},
value: {...CONST.DEFAULT_ACCOUNT_DATA, isLoading: true},
},
],
successData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {loading: false},
value: {isLoading: false},
},
],
failureData: [
{
onyxMethod: CONST.ONYX.METHOD.MERGE,
key: ONYXKEYS.ACCOUNT,
value: {loading: false},
value: {isLoading: false},
},
],
});
Expand Down Expand Up @@ -177,7 +177,7 @@ function updateNewsletterSubscription(isSubscribed) {
* @returns {Promise}
*/
function setSecondaryLoginAndNavigate(login, password) {
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true});
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, isLoading: true});

return DeprecatedAPI.User_SecondaryLogin_Send({
email: login,
Expand All @@ -202,7 +202,7 @@ function setSecondaryLoginAndNavigate(login, password) {

Onyx.merge(ONYXKEYS.USER, {error});
}).finally(() => {
Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false});
Onyx.merge(ONYXKEYS.ACCOUNT, {isLoading: false});
});
}

Expand All @@ -215,7 +215,7 @@ function setSecondaryLoginAndNavigate(login, password) {
function validateLogin(accountID, validateCode) {
const isLoggedIn = !_.isEmpty(sessionAuthToken);
const redirectRoute = isLoggedIn ? ROUTES.getReportRoute(currentlyViewedReportID) : ROUTES.HOME;
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true});
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, isLoading: true});

DeprecatedAPI.ValidateEmail({
accountID,
Expand All @@ -236,7 +236,7 @@ function validateLogin(accountID, validateCode) {
Onyx.merge(ONYXKEYS.ACCOUNT, {error});
}
}).finally(() => {
Onyx.merge(ONYXKEYS.ACCOUNT, {loading: false});
Onyx.merge(ONYXKEYS.ACCOUNT, {isLoading: false});
Navigation.navigate(redirectRoute);
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/signin/LoginForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class LoginForm extends React.Component {
});

// Check if this login has an account associated with it or not
Session.fetchAccountDetails(isValidPhoneLogin ? phoneLogin : login);
Session.beginSignIn(isValidPhoneLogin ? phoneLogin : login);
}

render() {
Expand Down
5 changes: 1 addition & 4 deletions src/pages/signin/ResendValidationForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ class ResendValidationForm extends React.Component {
</View>
<View style={[styles.mv5]}>
<Text>
{this.props.translate('resendValidationForm.weSentYouMagicSignInLink', {
login,
loginType,
})}
{this.props.translate('resendValidationForm.weSentYouMagicSignInLink', {login, loginType})}
</Text>
</View>
{!_.isEmpty(this.state.formSuccess) && (
Expand Down
1 change: 0 additions & 1 deletion tests/actions/ReportTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ describe('actions/Report', () => {

it('should be updated correctly when new comments are added, deleted or marked as unread', () => {
const REPORT_ID = 1;

let report;
Onyx.connect({
key: `${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/NetworkTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ test('Request will not run until credentials are read from Onyx', () => {
const spyHttpUtilsXhr = jest.spyOn(HttpUtils, 'xhr').mockImplementation(() => Promise.resolve({}));

// When we make a request
Session.fetchAccountDetails(TEST_USER_LOGIN);
Session.beginSignIn(TEST_USER_LOGIN);

// Then we should expect that no requests have been made yet
expect(spyHttpUtilsXhr).not.toHaveBeenCalled();
Expand Down
2 changes: 1 addition & 1 deletion tests/utils/TestHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function signInWithTestUser(accountID = 1, login = '[email protected]', password = '
}));

// Simulate user entering their login and populating the credentials.login
Session.fetchAccountDetails(login);
Session.beginSignIn(login);
return waitForPromisesToResolve()
.then(() => {
// First call to Authenticate
Expand Down

0 comments on commit f72ce58

Please sign in to comment.