Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
make login button disabled during request
Browse files Browse the repository at this point in the history
  • Loading branch information
doowzs committed Mar 2, 2019
1 parent 0628db8 commit c71172c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"ios",
"android"
],
"version": "0.2.1",
"version": "0.2.2",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"splash": {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@expo/samples": "2.1.1",
"axios": "^0.18.0",
"expo": "^32.0.0",
"js-base64": "^2.5.1",
"native-base": "^2.12.0",
"querystring": "^0.2.0",
"react": "16.5.0",
Expand Down
4 changes: 4 additions & 0 deletions screens/LoginScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default class LoginScreen extends React.Component {
this.state = {
username: '',
password: '',
disableAuthButton: false,
}
}

Expand Down Expand Up @@ -65,6 +66,7 @@ export default class LoginScreen extends React.Component {
/>
</Item>
<Button iconLeft full success
disabled={this.state.disableAuthButton}
style={[styles.rounded, styles.auth_button]}
onPress={this._handleLogin.bind(this)}
>
Expand All @@ -81,6 +83,7 @@ export default class LoginScreen extends React.Component {

_handleLogin = async () => {
try {
this.setState({ disableAuthButton: true });
let username = this.state.username, password = this.state.password;
if (!username || !password) {
Alert.alert("Error", "Username and password must be set.");
Expand All @@ -94,6 +97,7 @@ export default class LoginScreen extends React.Component {
"Status: " + (status ? status : "NULL")
+ "\nMessage: " + (message ? message : "NULL")
);
this.setState({ disableAuthButton: false });
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion services/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from 'axios';
import { Alert, AsyncStorage } from 'react-native';
import { Constants } from 'expo';
import { stringify } from 'querystring';
import { Base64 } from 'js-base64';

import * as Config from './config';

Expand Down Expand Up @@ -36,7 +37,7 @@ export const login = async (username, password) => {
const params = {
grant_type: 'password',
client_id: Config.clientID,
client_secret: atob(Config.clientSecret),
client_secret: Base64.decode(Config.clientSecret),
username: username,
password: password
};
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4192,6 +4192,11 @@ jest@^23.6.0:
import-local "^1.0.0"
jest-cli "^23.6.0"

js-base64@^2.5.1:
version "2.5.1"
resolved "http://registry.npm.taobao.org/js-base64/download/js-base64-2.5.1.tgz#1efa39ef2c5f7980bb1784ade4a8af2de3291121"
integrity sha1-Hvo57yxfeYC7F4St5KivLeMpESE=

"js-tokens@^3.0.0 || ^4.0.0", js-tokens@^4.0.0:
version "4.0.0"
resolved "http://registry.npm.taobao.org/js-tokens/download/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
Expand Down

0 comments on commit c71172c

Please sign in to comment.