/
quote-reposts-modal.component.ts
73 lines (63 loc) · 2.1 KB
/
quote-reposts-modal.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { Component, OnInit, Input } from "@angular/core";
import { BackendApiService } from "../backend-api.service";
import { GlobalVarsService } from "../global-vars.service";
import { BsModalRef } from "ngx-bootstrap/modal";
import { InfiniteScroller } from "../infinite-scroller";
import { IAdapter, IDatasource } from "ngx-ui-scroll";
@Component({
selector: "quote-reposts-modal",
templateUrl: "./quote-reposts-modal.component.html",
})
export class QuoteRepostsModalComponent implements OnInit {
@Input() postHashHex: string;
diamonds = [];
loading = false;
errorLoading = false;
constructor(
private backendApi: BackendApiService,
public globalVars: GlobalVarsService,
public bsModalRef: BsModalRef
) {}
ngOnInit(): void {
this.loading = true;
}
// Infinite scroll metadata.
pageOffset = 0;
lastPage = null;
pageSize = 50;
getPage = (page: number) => {
// After we have filled the lastPage, do not honor any more requests.
if (this.lastPage != null && page > this.lastPage) {
return [];
}
this.loading = true;
return this.backendApi
.GetQuoteRepostsForPost(
this.globalVars.localNode,
this.postHashHex,
this.pageOffset,
this.pageSize,
this.globalVars.loggedInUser.PublicKeyBase58Check
)
.toPromise()
.then(
(res) => {
let quoteRepostsPage = res.QuoteReposts;
// Update the pageOffset now that we have successfully fetched a page.
this.pageOffset += quoteRepostsPage.length;
// If we've hit the end of the followers with profiles, set last page and anonymous follower count.
if (quoteRepostsPage.length < this.pageSize) {
this.lastPage = page;
}
this.loading = false;
// Return the page.
return quoteRepostsPage;
},
(err) => {
this.errorLoading = true;
}
);
};
infiniteScroller: InfiniteScroller = new InfiniteScroller(this.pageSize, this.getPage, false);
datasource: IDatasource<IAdapter<any>> = this.infiniteScroller.getDatasource();
}