updates some signatures to be more verbose, fixes wrong type for attemptLogin

This commit is contained in:
Isaiah Becker-Mayer 2022-07-06 20:57:57 -04:00
parent ad0bd82bda
commit 7b7b19476c
2 changed files with 49 additions and 18 deletions

View File

@ -21,7 +21,7 @@ import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js";
import {CompleteSSOLoginViewModel} from "./CompleteSSOLoginViewModel.js"; import {CompleteSSOLoginViewModel} from "./CompleteSSOLoginViewModel.js";
import {LoadStatus} from "../../matrix/Client.js"; import {LoadStatus} from "../../matrix/Client.js";
import {SessionLoadViewModel} from "../SessionLoadViewModel.js"; import {SessionLoadViewModel} from "../SessionLoadViewModel.js";
import {PasswordLoginMethod, SSOLoginHelper, TokenLoginMethod} from "../../matrix/login"; import type {PasswordLoginMethod, SSOLoginHelper, TokenLoginMethod, ILoginMethod} from "../../matrix/login";
type Options = { type Options = {
defaultHomeserver: string; defaultHomeserver: string;
@ -44,9 +44,9 @@ export class LoginViewModel extends ViewModel<Options> {
private _abortHomeserverQueryTimeout?: () => void; private _abortHomeserverQueryTimeout?: () => void;
private _abortQueryOperation?: () => void; private _abortQueryOperation?: () => void;
private _hideHomeserver = false; private _hideHomeserver: boolean = false;
private _isBusy = false; private _isBusy: boolean = false;
private _errorMessage = ""; private _errorMessage: string = "";
constructor(options: Readonly<Options>) { constructor(options: Readonly<Options>) {
super(options); super(options);
@ -58,16 +58,45 @@ export class LoginViewModel extends ViewModel<Options> {
void this._initViewModels(); void this._initViewModels();
} }
get passwordLoginViewModel() { return this._passwordLoginViewModel; } get passwordLoginViewModel(): PasswordLoginViewModel {
get startSSOLoginViewModel() { return this._startSSOLoginViewModel; } return this._passwordLoginViewModel;
get completeSSOLoginViewModel(){ return this._completeSSOLoginViewModel; } }
get homeserver() { return this._homeserver; }
get resolvedHomeserver() { return this._loginOptions?.homeserver; } get startSSOLoginViewModel(): StartSSOLoginViewModel {
get errorMessage() { return this._errorMessage; } return this._startSSOLoginViewModel;
get showHomeserver() { return !this._hideHomeserver; } }
get loadViewModel() {return this._loadViewModel; }
get isBusy() { return this._isBusy; } get completeSSOLoginViewModel(): CompleteSSOLoginViewModel {
get isFetchingLoginOptions() { return !!this._abortQueryOperation; } return this._completeSSOLoginViewModel;
}
get homeserver(): string {
return this._homeserver;
}
get resolvedHomeserver(): string | undefined {
return this._loginOptions?.homeserver;
}
get errorMessage(): string {
return this._errorMessage;
}
get showHomeserver(): boolean {
return !this._hideHomeserver;
}
get loadViewModel(): SessionLoadViewModel {
return this._loadViewModel;
}
get isBusy(): boolean {
return this._isBusy;
}
get isFetchingLoginOptions(): boolean {
return !!this._abortQueryOperation;
}
goBack() { goBack() {
this.navigation.push("session"); this.navigation.push("session");
@ -80,7 +109,7 @@ export class LoginViewModel extends ViewModel<Options> {
this.childOptions( this.childOptions(
{ {
client: this._client, client: this._client,
attemptLogin: (loginMethod: PasswordLoginMethod) => this.attemptLogin(loginMethod), attemptLogin: (loginMethod: TokenLoginMethod) => this.attemptLogin(loginMethod),
loginToken: this._loginToken loginToken: this._loginToken
}))); })));
this.emitChange("completeSSOLoginViewModel"); this.emitChange("completeSSOLoginViewModel");
@ -118,7 +147,7 @@ export class LoginViewModel extends ViewModel<Options> {
this.emitChange("isBusy"); this.emitChange("isBusy");
} }
async attemptLogin(loginMethod: PasswordLoginMethod) { async attemptLogin(loginMethod: ILoginMethod) {
this._setBusy(true); this._setBusy(true);
await this._client.startWithLogin(loginMethod, {inspectAccountSetup: true}); await this._client.startWithLogin(loginMethod, {inspectAccountSetup: true});
const loadStatus = this._client.loadStatus; const loadStatus = this._client.loadStatus;
@ -171,7 +200,7 @@ export class LoginViewModel extends ViewModel<Options> {
this.emitChange("disposeViewModels"); this.emitChange("disposeViewModels");
} }
async setHomeserver(newHomeserver) { async setHomeserver(newHomeserver: string) {
this._homeserver = newHomeserver; this._homeserver = newHomeserver;
// clear everything set by queryHomeserver // clear everything set by queryHomeserver
this._loginOptions = undefined; this._loginOptions = undefined;

View File

@ -1,5 +1,7 @@
import {ILoginMethod} from "./LoginMethod";
import {PasswordLoginMethod} from "./PasswordLoginMethod"; import {PasswordLoginMethod} from "./PasswordLoginMethod";
import {SSOLoginHelper} from "./SSOLoginHelper"; import {SSOLoginHelper} from "./SSOLoginHelper";
import {TokenLoginMethod} from "./TokenLoginMethod"; import {TokenLoginMethod} from "./TokenLoginMethod";
export {PasswordLoginMethod, SSOLoginHelper, TokenLoginMethod};
export {PasswordLoginMethod, SSOLoginHelper, TokenLoginMethod, ILoginMethod};