2019-06-02 04:19:47 +05:30
|
|
|
import SimpleTile from "./SimpleTile.js";
|
2019-06-13 01:27:13 +05:30
|
|
|
import UpdateAction from "../UpdateAction.js";
|
2019-03-09 00:34:56 +05:30
|
|
|
|
|
|
|
export default class GapTile extends SimpleTile {
|
2019-03-09 05:10:03 +05:30
|
|
|
constructor(options, timeline) {
|
|
|
|
super(options);
|
2019-03-09 00:34:56 +05:30
|
|
|
this._timeline = timeline;
|
2019-03-09 05:10:03 +05:30
|
|
|
this._loading = false;
|
|
|
|
this._error = null;
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
async fill() {
|
|
|
|
// prevent doing this twice
|
|
|
|
if (!this._loading) {
|
|
|
|
this._loading = true;
|
2019-06-13 01:27:13 +05:30
|
|
|
this.emitUpdate("isLoading");
|
2019-03-09 05:10:03 +05:30
|
|
|
try {
|
2019-06-02 19:16:24 +05:30
|
|
|
await this._timeline.fillGap(this._entry, 10);
|
2019-03-09 05:10:03 +05:30
|
|
|
} catch (err) {
|
2019-06-02 19:16:24 +05:30
|
|
|
console.error(`timeline.fillGap(): ${err.message}:\n${err.stack}`);
|
2019-03-09 05:10:03 +05:30
|
|
|
this._error = err;
|
2019-06-13 01:27:13 +05:30
|
|
|
this.emitUpdate("error");
|
2019-06-02 19:16:24 +05:30
|
|
|
} finally {
|
|
|
|
this._loading = false;
|
2019-06-13 01:27:13 +05:30
|
|
|
this.emitUpdate("isLoading");
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-13 01:27:13 +05:30
|
|
|
updateEntry(entry) {
|
|
|
|
if (!entry.isGap) {
|
|
|
|
return UpdateAction.Remove();
|
|
|
|
} else {
|
|
|
|
return UpdateAction.Nothing();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-02 03:33:55 +05:30
|
|
|
get shape() {
|
|
|
|
return "gap";
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:10:03 +05:30
|
|
|
get isLoading() {
|
|
|
|
return this._loading;
|
|
|
|
}
|
|
|
|
|
2019-06-02 03:33:55 +05:30
|
|
|
get isUp() {
|
|
|
|
return this._entry.direction.isBackward;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isDown() {
|
|
|
|
return this._entry.direction.isForward;
|
2019-03-09 05:10:03 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
get error() {
|
|
|
|
if (this._error) {
|
|
|
|
const dir = this._entry.prev_batch ? "previous" : "next";
|
|
|
|
return `Could not load ${dir} messages: ${this._error.message}`;
|
|
|
|
}
|
|
|
|
return null;
|
2019-03-09 00:34:56 +05:30
|
|
|
}
|
|
|
|
}
|