add logout button to session load error screen

This commit is contained in:
Bruno Windels 2021-10-28 11:47:31 +02:00
parent cbccca20d0
commit 68a6113c26
5 changed files with 27 additions and 11 deletions

View file

@ -153,6 +153,11 @@ export class SessionLoadViewModel extends ViewModel {
this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`);
}
async logout() {
await this._sessionContainer.logout();
this.navigation.push("session", true);
}
get accountSetupViewModel() {
return this._accountSetupViewModel;
}

View file

@ -57,16 +57,11 @@ export class SettingsViewModel extends ViewModel {
return this._sessionContainer.session;
}
logout() {
return this.logger.run("logout", async log => {
async logout() {
this._isLoggingOut = true;
await this._sessionContainer.logout();
this.emitChange("isLoggingOut");
try {
await this._session.logout(log);
} catch (err) {}
await this._sessionContainer.deleteSession(log);
this.navigation.push("session", true);
});
}
setupDehydratedDevice(key) {

View file

@ -107,6 +107,7 @@ export class Session {
return this._sessionInfo.userId;
}
/** @internal call SessionContainer.logout instead */
async logout(log = undefined) {
await this._hsApi.logout({log}).response();
}

View file

@ -367,6 +367,15 @@ export class SessionContainer {
return !this._reconnector;
}
logout() {
return this._platform.logger.run("logout", async log => {
try {
await this._session?.logout(log);
} catch (err) {}
await this.deleteSession(log);
});
}
dispose() {
if (this._reconnectSubscription) {
this._reconnectSubscription();

View file

@ -28,11 +28,17 @@ export class SessionLoadStatusView extends TemplateView {
onClick: () => vm.exportLogs()
}, vm.i18n`Export logs`);
});
const logoutButtonIfFailed = t.if(vm => vm.hasError, (t, vm) => {
return t.button({
onClick: () => vm.logout()
}, vm.i18n`Log out`);
});
return t.div({className: "SessionLoadStatusView"}, [
t.p({className: "status"}, [
spinner(t, {hidden: vm => !vm.loading}),
t.p(vm => vm.loadLabel),
exportLogsButtonIfFailed
exportLogsButtonIfFailed,
logoutButtonIfFailed
]),
t.ifView(vm => vm.accountSetupViewModel, vm => new AccountSetupView(vm.accountSetupViewModel)),
]);