typescriptify domain/LogoutViewModel.js

This commit is contained in:
Tushar 2022-02-25 16:45:07 +05:30
parent 7055f02f16
commit 17acda7741
3 changed files with 18 additions and 11 deletions

View File

@ -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<LogoutOptions> {
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<void> {
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 {

View File

@ -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";

View File

@ -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<O extends Options = Options> 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) {