forked from mystiq/hydrogen-web
Set busy state from login vm
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
784b06d500
commit
ff8417dfe2
4 changed files with 15 additions and 4 deletions
|
@ -117,11 +117,15 @@ export class LoginViewModel extends ViewModel {
|
||||||
|
|
||||||
async attemptLogin(loginMethod) {
|
async attemptLogin(loginMethod) {
|
||||||
this._toggleBusy(true);
|
this._toggleBusy(true);
|
||||||
|
this._passwordLoginViewModel?.toggleBusy(true);
|
||||||
|
this._startSSOLoginViewModel?.toggleBusy(true);
|
||||||
this._sessionContainer.startWithLogin(loginMethod);
|
this._sessionContainer.startWithLogin(loginMethod);
|
||||||
const loadStatus = this._sessionContainer.loadStatus;
|
const loadStatus = this._sessionContainer.loadStatus;
|
||||||
const handle = loadStatus.waitFor(status => status !== LoadStatus.Login);
|
const handle = loadStatus.waitFor(status => status !== LoadStatus.Login);
|
||||||
await handle.promise;
|
await handle.promise;
|
||||||
this._toggleBusy(false);
|
this._toggleBusy(false);
|
||||||
|
this._passwordLoginViewModel?.toggleBusy(false);
|
||||||
|
this._startSSOLoginViewModel?.toggleBusy(false);
|
||||||
const status = loadStatus.get();
|
const status = loadStatus.get();
|
||||||
if (status === LoadStatus.LoginFailed) {
|
if (status === LoadStatus.LoginFailed) {
|
||||||
return this._sessionContainer.loginFailure;
|
return this._sessionContainer.loginFailure;
|
||||||
|
|
|
@ -30,15 +30,13 @@ export class PasswordLoginViewModel extends ViewModel {
|
||||||
|
|
||||||
get isBusy() { return this._isBusy; }
|
get isBusy() { return this._isBusy; }
|
||||||
|
|
||||||
_toggleBusy(state) {
|
toggleBusy(state) {
|
||||||
this._isBusy = state;
|
this._isBusy = state;
|
||||||
this.emitChange("isBusy");
|
this.emitChange("isBusy");
|
||||||
}
|
}
|
||||||
|
|
||||||
async login(username, password) {
|
async login(username, password) {
|
||||||
this._toggleBusy(true);
|
|
||||||
const status = await this._attemptLogin(this._loginOptions.password(username, password));
|
const status = await this._attemptLogin(this._loginOptions.password(username, password));
|
||||||
this._toggleBusy(false);
|
|
||||||
let error = "";
|
let error = "";
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case LoginFailure.Credentials:
|
case LoginFailure.Credentials:
|
||||||
|
|
|
@ -20,6 +20,14 @@ export class StartSSOLoginViewModel extends ViewModel{
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
super(options);
|
super(options);
|
||||||
this._sso = options.loginOptions.sso;
|
this._sso = options.loginOptions.sso;
|
||||||
|
this._isBusy = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get isBusy() { return this._isBusy; }
|
||||||
|
|
||||||
|
toggleBusy(state) {
|
||||||
|
this._isBusy = state;
|
||||||
|
this.emitChange("isBusy");
|
||||||
}
|
}
|
||||||
|
|
||||||
async startSSOLogin() {
|
async startSSOLogin() {
|
||||||
|
|
|
@ -57,7 +57,8 @@ class StartSSOLoginView extends TemplateView {
|
||||||
t.button({
|
t.button({
|
||||||
className: "StartSSOLoginView_button button-action secondary",
|
className: "StartSSOLoginView_button button-action secondary",
|
||||||
type: "button",
|
type: "button",
|
||||||
onClick: () => vm.startSSOLogin()
|
onClick: () => vm.startSSOLogin(),
|
||||||
|
disabled: vm => vm.isBusy
|
||||||
}, vm.i18n`Log in with SSO`)
|
}, vm.i18n`Log in with SSO`)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue