forked from mystiq/hydrogen-web
typescriptify domain/LogoutViewModel.js
This commit is contained in:
parent
7055f02f16
commit
17acda7741
3 changed files with 18 additions and 11 deletions
|
@ -14,11 +14,18 @@ See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {ViewModel} from "./ViewModel";
|
import {Options, ViewModel} from "./ViewModel";
|
||||||
import {Client} from "../matrix/Client.js";
|
import {Client} from "../matrix/Client.js";
|
||||||
|
|
||||||
export class LogoutViewModel extends ViewModel {
|
type LogoutOptions = { sessionId: string; } & Options;
|
||||||
constructor(options) {
|
|
||||||
|
export class LogoutViewModel extends ViewModel<LogoutOptions> {
|
||||||
|
private _sessionId: string;
|
||||||
|
private _busy: boolean;
|
||||||
|
private _showConfirm: boolean;
|
||||||
|
private _error?: Error;
|
||||||
|
|
||||||
|
constructor(options: LogoutOptions) {
|
||||||
super(options);
|
super(options);
|
||||||
this._sessionId = options.sessionId;
|
this._sessionId = options.sessionId;
|
||||||
this._busy = false;
|
this._busy = false;
|
||||||
|
@ -26,19 +33,19 @@ export class LogoutViewModel extends ViewModel {
|
||||||
this._error = undefined;
|
this._error = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
get showConfirm() {
|
get showConfirm(): boolean {
|
||||||
return this._showConfirm;
|
return this._showConfirm;
|
||||||
}
|
}
|
||||||
|
|
||||||
get busy() {
|
get busy(): boolean {
|
||||||
return this._busy;
|
return this._busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
get cancelUrl() {
|
get cancelUrl(): string {
|
||||||
return this.urlCreator.urlForSegment("session", true);
|
return this.urlCreator.urlForSegment("session", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
async logout() {
|
async logout(): Promise<void> {
|
||||||
this._busy = true;
|
this._busy = true;
|
||||||
this._showConfirm = false;
|
this._showConfirm = false;
|
||||||
this.emitChange("busy");
|
this.emitChange("busy");
|
||||||
|
@ -53,7 +60,7 @@ export class LogoutViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get status() {
|
get status(): string {
|
||||||
if (this._error) {
|
if (this._error) {
|
||||||
return this.i18n`Could not log out of device: ${this._error.message}`;
|
return this.i18n`Could not log out of device: ${this._error.message}`;
|
||||||
} else {
|
} else {
|
|
@ -18,7 +18,7 @@ import {Client} from "../matrix/Client.js";
|
||||||
import {SessionViewModel} from "./session/SessionViewModel.js";
|
import {SessionViewModel} from "./session/SessionViewModel.js";
|
||||||
import {SessionLoadViewModel} from "./SessionLoadViewModel.js";
|
import {SessionLoadViewModel} from "./SessionLoadViewModel.js";
|
||||||
import {LoginViewModel} from "./login/LoginViewModel.js";
|
import {LoginViewModel} from "./login/LoginViewModel.js";
|
||||||
import {LogoutViewModel} from "./LogoutViewModel.js";
|
import {LogoutViewModel} from "./LogoutViewModel";
|
||||||
import {SessionPickerViewModel} from "./SessionPickerViewModel.js";
|
import {SessionPickerViewModel} from "./SessionPickerViewModel.js";
|
||||||
import {ViewModel} from "./ViewModel";
|
import {ViewModel} from "./ViewModel";
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import type {ILogger} from "../logging/types";
|
||||||
import type {Navigation} from "./navigation/Navigation";
|
import type {Navigation} from "./navigation/Navigation";
|
||||||
import type {URLRouter} from "./navigation/URLRouter";
|
import type {URLRouter} from "./navigation/URLRouter";
|
||||||
|
|
||||||
type Options = {
|
export type Options = {
|
||||||
platform: Platform
|
platform: Platform
|
||||||
logger: ILogger
|
logger: ILogger
|
||||||
urlCreator: URLRouter
|
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?
|
// 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.
|
// 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
|
// just concat for now
|
||||||
let result = "";
|
let result = "";
|
||||||
for (let i = 0; i < parts.length; ++i) {
|
for (let i = 0; i < parts.length; ++i) {
|
||||||
|
|
Loading…
Reference in a new issue