From 82ac10af9349b121b7a424c4e4803836723b2916 Mon Sep 17 00:00:00 2001 From: softsimon Date: Wed, 11 Mar 2020 18:04:57 +0700 Subject: [PATCH] Preload latest blocks until it fills the screen on inital load. closes #42 --- .../latest-blocks/latest-blocks.component.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/components/latest-blocks/latest-blocks.component.ts b/frontend/src/app/components/latest-blocks/latest-blocks.component.ts index 671e7f33f..65afc907b 100644 --- a/frontend/src/app/components/latest-blocks/latest-blocks.component.ts +++ b/frontend/src/app/components/latest-blocks/latest-blocks.component.ts @@ -15,6 +15,9 @@ export class LatestBlocksComponent implements OnInit, OnDestroy { isLoading = true; interval: any; + heightOfPageUntilBlocks = 430; + heightOfBlocksTableChunk = 470; + constructor( private electrsApiService: ElectrsApiService, private stateService: StateService, @@ -58,10 +61,16 @@ export class LatestBlocksComponent implements OnInit, OnDestroy { .subscribe((blocks) => { this.blocks = blocks; 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) { return; } @@ -70,6 +79,11 @@ export class LatestBlocksComponent implements OnInit, OnDestroy { .subscribe((blocks) => { this.blocks = this.blocks.concat(blocks); this.isLoading = false; + + const chunksLeft = chunks - 1; + if (chunksLeft > 0) { + this.loadMore(chunksLeft); + } }); }