Skip to content
This repository was archived by the owner on Mar 10, 2019. It is now read-only.

Commit c0149d0

Browse files
committed
Hide socials card if empty
1 parent 22a05a1 commit c0149d0

3 files changed

Lines changed: 35 additions & 25 deletions

File tree

WebContent/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ <h3 class="mdc-typography--body1 mdc-typography--adjust-margin">You can login wi
8080
</section>
8181
</div>
8282

83-
<div class="mdc-card mdc-layout-grid__cell mdc-layout-grid__cell--span-12" id="socialLogin">
83+
<div class="mdc-card mdc-layout-grid__cell mdc-layout-grid__cell--span-12" id="socialLogin"
84+
style="display: none">
8485
<section class="mdc-card__primary">
8586
<h1 class="mdc-card__title mdc-typography--title">Social login</h1>
8687
</section>

WebContent/index.js

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ class LoginManager {
154154
setupGoogle(appId) {
155155
if (appId === undefined) {
156156
this.googleSignIn.hide();
157+
return false;
157158
} else {
158159
$.getScript("https://apis.google.com/js/api:client.js", () => {
159160
this.googleSignIn.show();
@@ -168,12 +169,14 @@ class LoginManager {
168169
(error) => Notifier.error("Failed signing in with Google.", error));
169170
});
170171
});
172+
return true;
171173
}
172174
}
173175

174176
setupFacebook(appId) {
175177
if (appId === undefined) {
176178
this.facebookSignIn.hide();
179+
return false;
177180
} else {
178181
$.getScript("https://connect.facebook.net/en_US/sdk.js", () => {
179182
FB.init({
@@ -193,28 +196,33 @@ class LoginManager {
193196
scope: 'email,public_profile',
194197
}));
195198
});
199+
return true;
196200
}
197201
}
198202

199203
setupGitHub(appId) {
200204
if (appId === undefined) {
201205
this.githubSignIn.hide();
206+
return false;
202207
} else {
203208
this.githubSignIn.show();
204209
this.githubSignIn.on('click', () => {
205210
window.location = "https://github.com/login/oauth/authorize?scope=read:user,user:email&client_id=" + appId
206-
})
211+
});
212+
return true;
207213
}
208214
}
209215

210216
setupTwitter(appId) {
211217
if (appId === undefined) {
212218
this.twitterSignIn.hide();
219+
return false;
213220
} else {
214221
this.twitterSignIn.show();
215222
this.twitterSignIn.on('click', () => {
216223
window.location = "/TwitterStartAuthFlow"
217-
})
224+
});
225+
return true;
218226
}
219227
}
220228

@@ -401,20 +409,12 @@ class LoginManager {
401409
else localStorage['ssp'] = data.ssp;
402410

403411
if (data.ip) {
404-
if (data.next === "game") {
405-
window.location = "/games/?gid=" + data.gid;
406-
} else {
407-
window.location = "/games/";
408-
}
412+
if (data.next === "game") window.location = "/games/?gid=" + data.gid;
413+
else window.location = "/games/";
409414
} else {
410415
const authConfig = data.aC;
411416
Notifier.debug(authConfig);
412417

413-
this.setupGoogle(authConfig.g);
414-
this.setupFacebook(authConfig.fb);
415-
this.setupGitHub(authConfig.gh);
416-
this.setupTwitter(authConfig.tw);
417-
418418
if ("pw" in authConfig) {
419419
this.pyxEmail.parent().show();
420420
this.pyxRegister.show();
@@ -423,17 +423,26 @@ class LoginManager {
423423
this.pyxRegister.hide();
424424
}
425425

426-
switch (getURLParameter("aT")) {
427-
case "gh":
428-
const token = Cookies.getJSON("PYX-Github-Token");
429-
Cookies.remove("PYX-Github-Token");
430-
this._githubSuccess(token);
431-
break;
432-
case "tw":
433-
const tokens = Cookies.getJSON("PYX-Twitter-Token");
434-
Cookies.remove("PYX-Twitter-Token");
435-
this._twitterSuccess(tokens);
436-
break;
426+
if (!this.setupGoogle(authConfig.g)
427+
&& !this.setupFacebook(authConfig.fb)
428+
&& !this.setupGitHub(authConfig.gh)
429+
&& !this.setupTwitter(authConfig.tw)) {
430+
431+
this._socials.hide();
432+
} else {
433+
this._socials.show();
434+
switch (getURLParameter("aT")) {
435+
case "gh":
436+
const token = Cookies.getJSON("PYX-Github-Token");
437+
Cookies.remove("PYX-Github-Token");
438+
this._githubSuccess(token);
439+
break;
440+
case "tw":
441+
const tokens = Cookies.getJSON("PYX-Twitter-Token");
442+
Cookies.remove("PYX-Twitter-Token");
443+
this._twitterSuccess(tokens);
444+
break;
445+
}
437446
}
438447
}
439448
}, null,

src/main/java/com/gianlu/pyxreloaded/singletons/Preferences.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private JsonElement get(String key) {
7272
parent = parent.getAsJsonObject(path);
7373
}
7474

75-
return parent.get(lastPath);
75+
return parent == null ? null : parent.get(lastPath);
7676
}
7777

7878
@NotNull

0 commit comments

Comments
 (0)