typescript-ifying StartSSOLoginViewModel

This commit is contained in:
Isaiah Becker-Mayer 2022-08-14 11:14:54 -07:00
parent 749e038a47
commit 53c4ecb69b
2 changed files with 22 additions and 12 deletions

View File

@ -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<SegmentType, Options> {
return this._passwordLoginViewModel;
}
get startSSOLoginViewModel(): StartSSOLoginViewModel {
get startSSOLoginViewModel(): StartSSOLoginViewModel | undefined {
return this._startSSOLoginViewModel;
}

View File

@ -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<void> {
await this.platform.settingsStorage.setString("sso_ongoing_login_homeserver", this._sso!.homeserver);
const link = this._sso!.createSSORedirectURL(this.urlCreator.createSSOCallbackURL());
this.platform.openUrl(link);
}
}