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

Integrated latest changes #40

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
use this.api() to reference window.gapi consistently
  • Loading branch information
joelvh committed Mar 9, 2019
commit 841bed85f02857ad338fca3ca949d7577f400513
46 changes: 25 additions & 21 deletions src/react-google-picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,40 +58,44 @@ export default class GoogleChooser extends React.Component {
}
}

isGoogleReady() {
return !!window.gapi;
api () {
return window.gapi
}

isGoogleAuthReady() {
return !!window.gapi.auth;
isGoogleReady () {
return !!this.api()
}

isGooglePickerReady() {
return !!window.google.picker;
isGoogleAuthReady () {
return !!this.api().auth
}

onApiLoad() {
window.gapi.load('auth');
window.gapi.load('picker');
isGooglePickerReady () {
return !!this.api().picker
}

doAuth(callback) {
window.gapi.auth.authorize({
client_id: this.props.clientId,
scope: this.props.scope,
immediate: this.props.authImmediate
},
callback
);
onApiLoad () {
this.api().load('auth')
this.api().load('picker')
}

doAuth (callback) {
this.api().auth.authorize({
client_id: this.props.clientId,
scope: this.props.scope,
immediate: this.props.authImmediate
},
callback
)
}

onChoose() {
onChoose () {
if (!this.isGoogleReady() || !this.isGoogleAuthReady() || !this.isGooglePickerReady() || this.props.disabled) {
return null;
return null
}

const token = window.gapi.auth.getToken();
const oauthToken = token && token.access_token;
const token = this.api().auth.getToken()
const oauthToken = token && token.access_token

if (oauthToken) {
this.createPicker(oauthToken);
Expand Down