Merge pull request #563 from vector-im/bwindels/exportlogsonsessionloadfail

add export logs button when session fails to load
This commit is contained in:
Bruno Windels 2021-10-26 15:35:50 +02:00 committed by GitHub
commit d9ecf38e42
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -102,8 +102,7 @@ export class SessionLoadViewModel extends ViewModel {
get loadLabel() { get loadLabel() {
const sc = this._sessionContainer; const sc = this._sessionContainer;
const error = this._error || (sc && sc.loadError); const error = this._getError();
if (error || (sc && sc.loadStatus.get() === LoadStatus.Error)) { if (error || (sc && sc.loadStatus.get() === LoadStatus.Error)) {
return `Something went wrong: ${error && error.message}.`; return `Something went wrong: ${error && error.message}.`;
} }
@ -124,4 +123,17 @@ export class SessionLoadViewModel extends ViewModel {
return `Preparing…`; 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`);
}
} }

View file

@ -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 */ Just a spinner and a label, meant to be used as a paragraph */
export class SessionLoadStatusView extends TemplateView { export class SessionLoadStatusView extends TemplateView {
render(t) { 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"}, [ return t.div({className: "SessionLoadStatusView"}, [
spinner(t, {hiddenWithLayout: vm => !vm.loading}), spinner(t, {hiddenWithLayout: vm => !vm.loading}),
t.p(vm => vm.loadLabel) t.p([vm => vm.loadLabel, exportLogsButtonIfFailed])
]); ]);
} }
} }