From 53c4ecb69b36fa6963bd9a538c7d986c64059596 Mon Sep 17 00:00:00 2001 From: Isaiah Becker-Mayer Date: Sun, 14 Aug 2022 11:14:54 -0700 Subject: [PATCH] typescript-ifying StartSSOLoginViewModel --- src/domain/login/LoginViewModel.ts | 4 +-- ...ViewModel.js => StartSSOLoginViewModel.ts} | 30 ++++++++++++------- 2 files changed, 22 insertions(+), 12 deletions(-) rename src/domain/login/{StartSSOLoginViewModel.js => StartSSOLoginViewModel.ts} (56%) diff --git a/src/domain/login/LoginViewModel.ts b/src/domain/login/LoginViewModel.ts index 40f4b5f7..43f0334a 100644 --- a/src/domain/login/LoginViewModel.ts +++ b/src/domain/login/LoginViewModel.ts @@ -17,7 +17,7 @@ limitations under the License. import {Client} from "../../matrix/Client.js"; import {Options as BaseOptions, ViewModel} from "../ViewModel"; import {PasswordLoginViewModel} from "./PasswordLoginViewModel"; -import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel.js"; +import {StartSSOLoginViewModel} from "./StartSSOLoginViewModel"; import {CompleteSSOLoginViewModel} from "./CompleteSSOLoginViewModel.js"; import {LoadStatus} from "../../matrix/Client.js"; import {SessionLoadViewModel} from "../SessionLoadViewModel.js"; @@ -64,7 +64,7 @@ export class LoginViewModel extends ViewModel { return this._passwordLoginViewModel; } - get startSSOLoginViewModel(): StartSSOLoginViewModel { + get startSSOLoginViewModel(): StartSSOLoginViewModel | undefined { return this._startSSOLoginViewModel; } diff --git a/src/domain/login/StartSSOLoginViewModel.js b/src/domain/login/StartSSOLoginViewModel.ts similarity index 56% rename from src/domain/login/StartSSOLoginViewModel.js rename to src/domain/login/StartSSOLoginViewModel.ts index dba0bcb5..b85bec71 100644 --- a/src/domain/login/StartSSOLoginViewModel.js +++ b/src/domain/login/StartSSOLoginViewModel.ts @@ -14,25 +14,35 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {ViewModel} from "../ViewModel"; +import type {SSOLoginHelper} from "../../matrix/login"; +import {Options as BaseOptions, ViewModel} from "../ViewModel"; +import type {LoginOptions} from "./LoginViewModel"; + + +type Options = { + loginOptions: LoginOptions | undefined; +} & BaseOptions; export class StartSSOLoginViewModel extends ViewModel{ - constructor(options) { + private _sso?: SSOLoginHelper; + private _isBusy = false; + + constructor(options: Options) { super(options); - this._sso = options.loginOptions.sso; + this._sso = options.loginOptions!.sso; this._isBusy = false; } - - get isBusy() { return this._isBusy; } - - setBusy(status) { + + get isBusy(): boolean { return this._isBusy; } + + setBusy(status: boolean): void { this._isBusy = status; this.emitChange("isBusy"); } - async startSSOLogin() { - await this.platform.settingsStorage.setString("sso_ongoing_login_homeserver", this._sso.homeserver); - const link = this._sso.createSSORedirectURL(this.urlCreator.createSSOCallbackURL()); + async startSSOLogin(): Promise { + await this.platform.settingsStorage.setString("sso_ongoing_login_homeserver", this._sso!.homeserver); + const link = this._sso!.createSSORedirectURL(this.urlCreator.createSSOCallbackURL()); this.platform.openUrl(link); } }