From 17acda77414fe0d4ca5ae74c949dfd65b1e75a20 Mon Sep 17 00:00:00 2001 From: Tushar Date: Fri, 25 Feb 2022 16:45:07 +0530 Subject: [PATCH] typescriptify domain/LogoutViewModel.js --- ...{LogoutViewModel.js => LogoutViewModel.ts} | 23 ++++++++++++------- src/domain/RootViewModel.js | 2 +- src/domain/ViewModel.ts | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) rename src/domain/{LogoutViewModel.js => LogoutViewModel.ts} (76%) diff --git a/src/domain/LogoutViewModel.js b/src/domain/LogoutViewModel.ts similarity index 76% rename from src/domain/LogoutViewModel.js rename to src/domain/LogoutViewModel.ts index 24ca440e..3edfcad5 100644 --- a/src/domain/LogoutViewModel.js +++ b/src/domain/LogoutViewModel.ts @@ -14,11 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */ -import {ViewModel} from "./ViewModel"; +import {Options, ViewModel} from "./ViewModel"; import {Client} from "../matrix/Client.js"; -export class LogoutViewModel extends ViewModel { - constructor(options) { +type LogoutOptions = { sessionId: string; } & Options; + +export class LogoutViewModel extends ViewModel { + private _sessionId: string; + private _busy: boolean; + private _showConfirm: boolean; + private _error?: Error; + + constructor(options: LogoutOptions) { super(options); this._sessionId = options.sessionId; this._busy = false; @@ -26,19 +33,19 @@ export class LogoutViewModel extends ViewModel { this._error = undefined; } - get showConfirm() { + get showConfirm(): boolean { return this._showConfirm; } - get busy() { + get busy(): boolean { return this._busy; } - get cancelUrl() { + get cancelUrl(): string { return this.urlCreator.urlForSegment("session", true); } - async logout() { + async logout(): Promise { this._busy = true; this._showConfirm = false; this.emitChange("busy"); @@ -53,7 +60,7 @@ export class LogoutViewModel extends ViewModel { } } - get status() { + get status(): string { if (this._error) { return this.i18n`Could not log out of device: ${this._error.message}`; } else { diff --git a/src/domain/RootViewModel.js b/src/domain/RootViewModel.js index 642e43f4..2711cd2f 100644 --- a/src/domain/RootViewModel.js +++ b/src/domain/RootViewModel.js @@ -18,7 +18,7 @@ import {Client} from "../matrix/Client.js"; import {SessionViewModel} from "./session/SessionViewModel.js"; import {SessionLoadViewModel} from "./SessionLoadViewModel.js"; import {LoginViewModel} from "./login/LoginViewModel.js"; -import {LogoutViewModel} from "./LogoutViewModel.js"; +import {LogoutViewModel} from "./LogoutViewModel"; import {SessionPickerViewModel} from "./SessionPickerViewModel.js"; import {ViewModel} from "./ViewModel"; diff --git a/src/domain/ViewModel.ts b/src/domain/ViewModel.ts index 458b2840..cfe22326 100644 --- a/src/domain/ViewModel.ts +++ b/src/domain/ViewModel.ts @@ -29,7 +29,7 @@ import type {ILogger} from "../logging/types"; import type {Navigation} from "./navigation/Navigation"; import type {URLRouter} from "./navigation/URLRouter"; -type Options = { +export type Options = { platform: Platform logger: ILogger urlCreator: URLRouter @@ -95,7 +95,7 @@ export class ViewModel extends EventEmitter<{change // // translated string should probably always be bindings, unless we're fine with a refresh when changing the language? // we probably are, if we're using routing with a url, we could just refresh. - i18n(parts: string[], ...expr: any[]) { + i18n(parts: TemplateStringsArray, ...expr: any[]) { // just concat for now let result = ""; for (let i = 0; i < parts.length; ++i) {