From 7ef19e0ead7ca57e659cb8f09d0e5302b6bff9dc Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Tue, 26 Oct 2021 15:30:52 +0200 Subject: [PATCH] add export logs button when session fails to load --- src/domain/SessionLoadViewModel.js | 16 ++++++++++++++-- .../web/ui/login/SessionLoadStatusView.js | 7 ++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/domain/SessionLoadViewModel.js b/src/domain/SessionLoadViewModel.js index 10cbb851..f7cf8285 100644 --- a/src/domain/SessionLoadViewModel.js +++ b/src/domain/SessionLoadViewModel.js @@ -102,8 +102,7 @@ export class SessionLoadViewModel extends ViewModel { get loadLabel() { const sc = this._sessionContainer; - const error = this._error || (sc && sc.loadError); - + const error = this._getError(); if (error || (sc && sc.loadStatus.get() === LoadStatus.Error)) { return `Something went wrong: ${error && error.message}.`; } @@ -124,4 +123,17 @@ export class SessionLoadViewModel extends ViewModel { return `Preparing…`; } + + _getError() { + return this._error || this._sessionContainer?.loadError; + } + + get hasError() { + return !!this._getError(); + } + + async exportLogs() { + const logExport = await this.logger.export(); + this.platform.saveFileAs(logExport.asBlob(), `hydrogen-logs-${this.platform.clock.now()}.json`); + } } diff --git a/src/platform/web/ui/login/SessionLoadStatusView.js b/src/platform/web/ui/login/SessionLoadStatusView.js index d3ff2c9a..3c22de9f 100644 --- a/src/platform/web/ui/login/SessionLoadStatusView.js +++ b/src/platform/web/ui/login/SessionLoadStatusView.js @@ -22,9 +22,14 @@ to show the current state of loading the session. Just a spinner and a label, meant to be used as a paragraph */ export class SessionLoadStatusView extends TemplateView { render(t) { + const exportLogsButtonIfFailed = t.if(vm => vm.hasError, (t, vm) => { + return t.button({ + onClick: () => vm.exportLogs() + }, vm.i18n`Export logs`); + }); return t.div({className: "SessionLoadStatusView"}, [ spinner(t, {hiddenWithLayout: vm => !vm.loading}), - t.p(vm => vm.loadLabel) + t.p([vm => vm.loadLabel, exportLogsButtonIfFailed]) ]); } }