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

Fix OAuth login loading state #24788

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
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
51 changes: 24 additions & 27 deletions templates/user/auth/signin_inner.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,30 @@

{{if and .OrderedOAuth2Names .OAuth2Providers}}
<hr class="ui divider"/>
<div class="oauth2 center">
<div id="oauth2-login-loader" class="ui disabled centered loader"></div>
<div>
<div id="oauth2-login-navigator" class="gt-df gt-jc">
<span class="gt-self-center gt-mr-3">{{.locale.Tr "sign_in_with"}}</span>
<div class="gt-df gt-fw gt-gap-4">
{{range $key := .OrderedOAuth2Names}}
{{$provider := index $.OAuth2Providers $key}}
<a class="{{$provider.Name}} silenced oauth-login-link" href="{{AppSubUrl}}/user/oauth2/{{$key}}" data-tooltip-content="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}">
{{if eq $provider.Name "github"}}
{{svg "octicon-mark-github" 40}}
{{else if eq $provider.Name "gitlab"}}
{{svg "gitea-gitlab" 40}}
{{else if eq $provider.Name "openidConnect"}}
{{svg "gitea-openid" 40}}
{{else}}
<img
class="gt-object-contain"
width="40"
height="40"
alt="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}"
src="{{AppSubUrl}}{{$provider.Image}}"
>
{{end}}
</a>
{{end}}
</div>
<div id="oauth2-login-navigator">
<div id="oauth2-login-navigator-inner" class="gt-df gt-jc">
<span class="gt-self-center gt-mr-3">{{.locale.Tr "sign_in_with"}}</span>
<div class="gt-df gt-fw gt-gap-4">
{{range $key := .OrderedOAuth2Names}}
{{$provider := index $.OAuth2Providers $key}}
<a class="{{$provider.Name}} silenced oauth-login-link" href="{{AppSubUrl}}/user/oauth2/{{$key}}" data-tooltip-content="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}">
{{if eq $provider.Name "github"}}
{{svg "octicon-mark-github" 40}}
{{else if eq $provider.Name "gitlab"}}
{{svg "gitea-gitlab" 40}}
{{else if eq $provider.Name "openidConnect"}}
{{svg "gitea-openid" 40}}
{{else}}
<img
class="gt-object-contain"
width="40"
height="40"
alt="{{$provider.DisplayName}}{{if eq $provider.Name "openidConnect"}} ({{$key}}){{end}}"
src="{{AppSubUrl}}{{$provider.Image}}"
>
{{end}}
</a>
{{end}}
</div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions web_src/css/modules/animations.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ code.language-math.is-loading::after {
height: 1.25rem;
}

#oauth2-login-navigator.is-loading::after {
silverwind marked this conversation as resolved.
Show resolved Hide resolved
width: 40px;
height: 40px;
}

@keyframes fadein {
0% {
opacity: 0;
Expand Down
34 changes: 16 additions & 18 deletions web_src/js/features/user-auth.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import $ from 'jquery';
import {hideElem, showElem} from '../utils/dom.js';

export function initUserAuthOauth2() {
const $oauth2LoginNav = $('#oauth2-login-navigator');
if ($oauth2LoginNav.length === 0) return;

$oauth2LoginNav.find('.oauth-login-image').on('click', () => {
const oauthLoader = $('#oauth2-login-loader');
const oauthNav = $('#oauth2-login-navigator');

hideElem(oauthNav);
oauthLoader.removeClass('disabled');

setTimeout(() => {
// recover previous content to let user try again
// usually redirection will be performed before this action
oauthLoader.addClass('disabled');
showElem(oauthNav);
}, 5000);
});
const outer = document.getElementById('oauth2-login-navigator');
if (!outer) return;
const inner = document.getElementById('oauth2-login-navigator-inner');

for (const link of outer.querySelectorAll('.oauth-login-link')) {
link.addEventListener('click', () => {
inner.classList.add('gt-invisible');
outer.classList.add('is-loading');
setTimeout(() => {
// recover previous content to let user try again
// usually redirection will be performed before this action
outer.classList.remove('is-loading');
inner.classList.remove('gt-invisible');
}, 5000);
});
}
}

export function initUserAuthLinkAccountView() {
Expand Down