Preload latest blocks until it fills the screen on inital load.
closes #42
This commit is contained in:
parent
f94007979b
commit
82ac10af93
@ -15,6 +15,9 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
|
|||||||
isLoading = true;
|
isLoading = true;
|
||||||
interval: any;
|
interval: any;
|
||||||
|
|
||||||
|
heightOfPageUntilBlocks = 430;
|
||||||
|
heightOfBlocksTableChunk = 470;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private electrsApiService: ElectrsApiService,
|
private electrsApiService: ElectrsApiService,
|
||||||
private stateService: StateService,
|
private stateService: StateService,
|
||||||
@ -58,10 +61,16 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
|
|||||||
.subscribe((blocks) => {
|
.subscribe((blocks) => {
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
|
||||||
|
const spaceForBlocks = window.innerHeight - this.heightOfPageUntilBlocks;
|
||||||
|
const chunks = Math.ceil(spaceForBlocks / this.heightOfBlocksTableChunk) - 1;
|
||||||
|
if (chunks > 0) {
|
||||||
|
this.loadMore(chunks);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadMore() {
|
loadMore(chunks = 0) {
|
||||||
if (this.isLoading) {
|
if (this.isLoading) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -70,6 +79,11 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
|
|||||||
.subscribe((blocks) => {
|
.subscribe((blocks) => {
|
||||||
this.blocks = this.blocks.concat(blocks);
|
this.blocks = this.blocks.concat(blocks);
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
|
||||||
|
const chunksLeft = chunks - 1;
|
||||||
|
if (chunksLeft > 0) {
|
||||||
|
this.loadMore(chunksLeft);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user