Telegram Web K with changes to work inside I2P
https://web.telegram.i2p/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.2 KiB
54 lines
1.2 KiB
3 years ago
|
/*
|
||
|
* https://github.com/morethanwords/tweb
|
||
|
* Copyright (C) 2019-2021 Eduard Kuzmenko
|
||
|
* https://github.com/morethanwords/tweb/blob/master/LICENSE
|
||
|
*/
|
||
|
|
||
|
import Scrollable from "../components/scrollable";
|
||
|
import { safeAssign } from "./object";
|
||
|
|
||
|
export default class ScrollableLoader {
|
||
|
public loading = false;
|
||
|
private scrollable: Scrollable;
|
||
|
private getPromise: () => Promise<any>;
|
||
|
private promise: Promise<any>;
|
||
|
private loaded = false;
|
||
|
|
||
|
constructor(options: {
|
||
|
scrollable: ScrollableLoader['scrollable'],
|
||
|
getPromise: ScrollableLoader['getPromise']
|
||
|
}) {
|
||
|
safeAssign(this, options);
|
||
|
|
||
|
options.scrollable.onScrolledBottom = () => {
|
||
|
this.load();
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public load() {
|
||
|
if(this.loaded) {
|
||
|
return Promise.resolve();
|
||
|
}
|
||
|
|
||
|
if(this.loading) {
|
||
|
return this.promise;
|
||
|
}
|
||
|
|
||
|
this.loading = true;
|
||
|
this.promise = this.getPromise().then(done => {
|
||
|
this.loading = false;
|
||
|
this.promise = undefined;
|
||
|
|
||
|
if(done) {
|
||
|
this.loaded = true;
|
||
|
this.scrollable.onScrolledBottom = null;
|
||
|
} else {
|
||
|
this.scrollable.checkForTriggers();
|
||
|
}
|
||
|
}, () => {
|
||
|
this.promise = undefined;
|
||
|
this.loading = false;
|
||
|
});
|
||
|
}
|
||
|
}
|