mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Fix errors and simplify code
This commit is contained in:
parent
8e2838264f
commit
220144898b
@ -26,21 +26,22 @@ export class GapTile extends SimpleTile {
|
|||||||
this._error = null;
|
this._error = null;
|
||||||
this._isAtTop = true;
|
this._isAtTop = true;
|
||||||
this._siblingChanged = false;
|
this._siblingChanged = false;
|
||||||
|
this._showSpinner = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fill() {
|
async fill() {
|
||||||
if (!this._loading && !this._entry.edgeReached) {
|
if (!this._loading && !this._entry.edgeReached) {
|
||||||
this._loading = true;
|
this._loading = true;
|
||||||
this._error = null;
|
this._error = null;
|
||||||
|
this._showSpinner = true;
|
||||||
this.emitChange("isLoading");
|
this.emitChange("isLoading");
|
||||||
try {
|
try {
|
||||||
await this._room.fillGap(this._entry, 10);
|
await this._room.fillGap(this._entry, 10);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`room.fillGap(): ${err.message}:\n${err.stack}`);
|
console.error(`room.fillGap(): ${err.message}:\n${err.stack}`);
|
||||||
this._error = err;
|
this._error = err;
|
||||||
this._loading = false;
|
|
||||||
this.emitChange("error");
|
|
||||||
if (err instanceof ConnectionError) {
|
if (err instanceof ConnectionError) {
|
||||||
|
this.emitChange("error");
|
||||||
/*
|
/*
|
||||||
We need to wait for reconnection here rather than in
|
We need to wait for reconnection here rather than in
|
||||||
notifyVisible() because when we return/throw here
|
notifyVisible() because when we return/throw here
|
||||||
@ -49,13 +50,13 @@ export class GapTile extends SimpleTile {
|
|||||||
resulting in multiple error entries in logs and elsewhere!
|
resulting in multiple error entries in logs and elsewhere!
|
||||||
*/
|
*/
|
||||||
await this._waitForReconnection();
|
await this._waitForReconnection();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
// rethrow so caller of this method
|
// rethrow so caller of this method
|
||||||
// knows not to keep calling this for now
|
// knows not to keep calling this for now
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
this._loading = false;
|
this._loading = false;
|
||||||
|
this._showSpinner = false;
|
||||||
this.emitChange("isLoading");
|
this.emitChange("isLoading");
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -128,13 +129,17 @@ export class GapTile extends SimpleTile {
|
|||||||
return this._loading;
|
return this._loading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get showSpinner() {
|
||||||
|
return this._showSpinner;
|
||||||
|
}
|
||||||
|
|
||||||
get error() {
|
get error() {
|
||||||
if (this._error) {
|
if (this._error) {
|
||||||
if (this._error instanceof ConnectionError) {
|
if (this._error instanceof ConnectionError) {
|
||||||
return { message: "Waiting for reconnection", showSpinner: true };
|
return "Waiting for reconnection";
|
||||||
}
|
}
|
||||||
const dir = this._entry.prev_batch ? "previous" : "next";
|
const dir = this._entry.prev_batch ? "previous" : "next";
|
||||||
return { message: `Could not load ${dir} messages: ${this._error.message}`, showSpinner: false };
|
return `Could not load ${dir} messages: ${this._error.message}`;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -30,24 +30,18 @@ export class GapView extends TemplateView {
|
|||||||
isAtTop: vm => vm.isAtTop,
|
isAtTop: vm => vm.isAtTop,
|
||||||
};
|
};
|
||||||
return t.li({ className }, [
|
return t.li({ className }, [
|
||||||
t.map(vm => vm.isLoading,
|
t.if(vm => vm.showSpinner, (t) => spinner(t)),
|
||||||
(isLoading, t, vm) => {
|
t.span(vm => {
|
||||||
let elements;
|
if (vm.error) {
|
||||||
const error = vm.error;
|
return vm.error;
|
||||||
if (error) {
|
}
|
||||||
elements = [t.strong(() => error.message)];
|
else if (vm.isLoading) {
|
||||||
if (error.showSpinner) {
|
return "Loading";
|
||||||
elements.unshift(spinner(t));
|
}
|
||||||
}
|
else {
|
||||||
}
|
return "Not Loading";
|
||||||
else if (isLoading) {
|
}
|
||||||
elements = [spinner(t), t.span(vm.i18n`Loading more messages …`)];
|
})
|
||||||
}
|
|
||||||
else {
|
|
||||||
elements = t.span(vm.i18n`Not loading!`);
|
|
||||||
}
|
|
||||||
return t.div({ className: "GapView__container" }, elements);
|
|
||||||
})
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user