Set busy state from login vm

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-08-20 20:31:22 +05:30
parent 784b06d500
commit ff8417dfe2
4 changed files with 15 additions and 4 deletions

View file

@ -117,11 +117,15 @@ export class LoginViewModel extends ViewModel {
async attemptLogin(loginMethod) {
this._toggleBusy(true);
this._passwordLoginViewModel?.toggleBusy(true);
this._startSSOLoginViewModel?.toggleBusy(true);
this._sessionContainer.startWithLogin(loginMethod);
const loadStatus = this._sessionContainer.loadStatus;
const handle = loadStatus.waitFor(status => status !== LoadStatus.Login);
await handle.promise;
this._toggleBusy(false);
this._passwordLoginViewModel?.toggleBusy(false);
this._startSSOLoginViewModel?.toggleBusy(false);
const status = loadStatus.get();
if (status === LoadStatus.LoginFailed) {
return this._sessionContainer.loginFailure;

View file

@ -30,15 +30,13 @@ export class PasswordLoginViewModel extends ViewModel {
get isBusy() { return this._isBusy; }
_toggleBusy(state) {
toggleBusy(state) {
this._isBusy = state;
this.emitChange("isBusy");
}
async login(username, password) {
this._toggleBusy(true);
const status = await this._attemptLogin(this._loginOptions.password(username, password));
this._toggleBusy(false);
let error = "";
switch (status) {
case LoginFailure.Credentials:

View file

@ -20,6 +20,14 @@ export class StartSSOLoginViewModel extends ViewModel{
constructor(options) {
super(options);
this._sso = options.loginOptions.sso;
this._isBusy = false;
}
get isBusy() { return this._isBusy; }
toggleBusy(state) {
this._isBusy = state;
this.emitChange("isBusy");
}
async startSSOLogin() {

View file

@ -57,7 +57,8 @@ class StartSSOLoginView extends TemplateView {
t.button({
className: "StartSSOLoginView_button button-action secondary",
type: "button",
onClick: () => vm.startSSOLogin()
onClick: () => vm.startSSOLogin(),
disabled: vm => vm.isBusy
}, vm.i18n`Log in with SSO`)
);
}