Merge pull request #710 from MiguelMedeiros/feature-next-previous-block-arrows
UI/UX: `Next` and `Previous` button arrows for block navigation.
This commit is contained in:
@@ -1,7 +1,39 @@
|
||||
<div class="container-xl" (window:resize)="onResize($event)">
|
||||
|
||||
<div class="title-block" id="block">
|
||||
<h1><ng-template [ngIf]="blockHeight === 0" i18n="block.genesis">Genesis </ng-template><ng-template [ngIf]="blockHeight" i18n="block.block">Block <a [routerLink]="['/block/' | relativeUrl, blockHash]">{{ blockHeight }}</a></ng-template></h1>
|
||||
<h1>
|
||||
<ng-template [ngIf]="blockHeight === 0" i18n="block.genesis">Genesis
|
||||
<div class="next-previous-blocks">
|
||||
<a *ngIf="showNextBlocklink" [routerLink]="['/block/' | relativeUrl, nextBlockHeight]" i18n-ngbTooltip="Next Block" ngbTooltip="Next Block" placement="bottom">
|
||||
<fa-icon [icon]="['fas', 'angle-left']" [fixedWidth]="true" i18n-title="dashboard.collapse" title="Collapse"></fa-icon>
|
||||
</a>
|
||||
<a [routerLink]="['/block/' | relativeUrl, blockHash]">{{ blockHeight }}</a>
|
||||
<span placement="bottom" class="disable">
|
||||
<fa-icon [icon]="['fas', 'angle-right']" [fixedWidth]="true" i18n-title="dashboard.collapse" title="Collapse"></fa-icon>
|
||||
</span>
|
||||
</div>
|
||||
</ng-template>
|
||||
<ng-template [ngIf]="blockHeight" i18n="block.block"> Block
|
||||
<div class="next-previous-blocks">
|
||||
<a *ngIf="showNextBlocklink" [routerLink]="['/block/' | relativeUrl, nextBlockHeight]" i18n-ngbTooltip="Next Block" ngbTooltip="Next Block" placement="bottom">
|
||||
<fa-icon [icon]="['fas', 'angle-left']" [fixedWidth]="true" i18n-title="dashboard.collapse" title="Collapse"></fa-icon>
|
||||
</a>
|
||||
<span *ngIf="!showNextBlocklink" placement="bottom" class="disable">
|
||||
<fa-icon [icon]="['fas', 'angle-left']" [fixedWidth]="true" i18n-title="dashboard.collapse" title="Collapse"></fa-icon>
|
||||
</span>
|
||||
<a [routerLink]="['/block/' | relativeUrl, blockHash]">{{ blockHeight }}</a>
|
||||
<a *ngIf="showPreviousBlocklink" [routerLink]="['/block/' | relativeUrl, previousBlockHeight]" i18n-ngbTooltip="Previous Block" ngbTooltip="Previous Block" placement="bottom">
|
||||
<fa-icon [icon]="['fas', 'angle-right']" [fixedWidth]="true" i18n-title="dashboard.collapse" title="Collapse"></fa-icon>
|
||||
</a>
|
||||
<span *ngIf="!showPreviousBlocklink" placement="bottom" class="disable">
|
||||
<fa-icon [icon]="['fas', 'angle-right']" [fixedWidth]="true" i18n-title="dashboard.collapse" title="Collapse"></fa-icon>
|
||||
</span>
|
||||
</div>
|
||||
</ng-template>
|
||||
</h1>
|
||||
|
||||
<div class="grow"></div>
|
||||
|
||||
<button [routerLink]="['/' | relativeUrl]" class="btn btn-sm">✕</button>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -44,6 +44,11 @@ h1 {
|
||||
float: left;
|
||||
margin-right: 10px;
|
||||
}
|
||||
a {
|
||||
&:hover, &:focus{
|
||||
text-decoration: none;;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.address-link {
|
||||
@@ -110,4 +115,29 @@ h1 {
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.grow {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
.next-previous-blocks {
|
||||
font-size: 36px;
|
||||
display: inline-block;
|
||||
vertical-align: bottom;
|
||||
|
||||
a {
|
||||
color: #1ad8f4;
|
||||
&:hover, &:focus {
|
||||
color: #09a3ba;
|
||||
display: inline-block;
|
||||
// transform: scale(1.2);
|
||||
// transition: 150ms all ease-in-out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.disable {
|
||||
font-size: 36px;
|
||||
color: #393e5c73;
|
||||
}
|
||||
@@ -18,6 +18,8 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
network = '';
|
||||
block: Block;
|
||||
blockHeight: number;
|
||||
previousBlockHeight: number;
|
||||
nextBlockHeight: number;
|
||||
blockHash: string;
|
||||
isLoadingBlock = true;
|
||||
latestBlock: Block;
|
||||
@@ -33,6 +35,8 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
itemsPerPage: number;
|
||||
txsLoadingStatus$: Observable<number>;
|
||||
showDetails = false;
|
||||
showPreviousBlocklink = true;
|
||||
showNextBlocklink = true;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
@@ -69,6 +73,9 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
|
||||
if (history.state.data && history.state.data.blockHeight) {
|
||||
this.blockHeight = history.state.data.blockHeight;
|
||||
this.previousBlockHeight = history.state.data.blockHeight - 1;
|
||||
this.nextBlockHeight = history.state.data.blockHeight + 1;
|
||||
this.setNextAndPreviousBlockLink();
|
||||
}
|
||||
|
||||
let isBlockHeight = false;
|
||||
@@ -81,6 +88,9 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
|
||||
if (history.state.data && history.state.data.block) {
|
||||
this.blockHeight = history.state.data.block.height;
|
||||
this.previousBlockHeight = history.state.data.block.height - 1;
|
||||
this.nextBlockHeight = history.state.data.block.height + 1;
|
||||
this.setNextAndPreviousBlockLink();
|
||||
return of(history.state.data.block);
|
||||
} else {
|
||||
this.isLoadingBlock = true;
|
||||
@@ -110,6 +120,10 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
tap((block: Block) => {
|
||||
this.block = block;
|
||||
this.blockHeight = block.height;
|
||||
this.previousBlockHeight = block.height - 1;
|
||||
this.nextBlockHeight = block.height + 1;
|
||||
this.setNextAndPreviousBlockLink();
|
||||
|
||||
this.seoService.setTitle($localize`:@@block.component.browser-title:Block ${block.height}:BLOCK_HEIGHT:: ${block.id}:BLOCK_ID:`);
|
||||
this.isLoadingBlock = false;
|
||||
if (block.coinbaseTx) {
|
||||
@@ -148,7 +162,10 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
|
||||
this.stateService.blocks$
|
||||
.subscribe(([block]) => this.latestBlock = block);
|
||||
.subscribe(([block]) => {
|
||||
this.latestBlock = block;
|
||||
this.setNextAndPreviousBlockLink();
|
||||
});
|
||||
|
||||
this.stateService.networkChanged$
|
||||
.subscribe((network) => this.network = network);
|
||||
@@ -160,6 +177,23 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
this.showDetails = false;
|
||||
}
|
||||
});
|
||||
|
||||
this.stateService.keyNavigation$.subscribe((event) => {
|
||||
if (this.showPreviousBlocklink) {
|
||||
if (event.key === 'ArrowRight') {
|
||||
if (this.previousBlockHeight >= 0) {
|
||||
this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', this.previousBlockHeight]);
|
||||
this.blockHeight = this.previousBlockHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.showNextBlocklink) {
|
||||
if (event.key === 'ArrowLeft') {
|
||||
this.router.navigate([(this.network ? '/' + this.network : '') + '/block/', this.nextBlockHeight]);
|
||||
this.blockHeight = this.nextBlockHeight;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
@@ -229,4 +263,18 @@ export class BlockComponent implements OnInit, OnDestroy {
|
||||
onResize(event: any) {
|
||||
this.paginationMaxSize = event.target.innerWidth < 670 ? 3 : 5;
|
||||
}
|
||||
setNextAndPreviousBlockLink(){
|
||||
if (this.latestBlock && this.blockHeight){
|
||||
if (this.blockHeight === 0){
|
||||
this.showPreviousBlocklink = false;
|
||||
} else {
|
||||
this.showPreviousBlocklink = true;
|
||||
}
|
||||
if (this.latestBlock.height && this.latestBlock.height === this.blockHeight) {
|
||||
this.showNextBlocklink = false;
|
||||
}else{
|
||||
this.showNextBlocklink = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user