Merge pull request #1024 from nymkappa/feature/blocks-mouse-scroll

User can drag the blockchain blocks horizontally with the mouse
This commit is contained in:
softsimon 2021-12-19 12:59:04 +04:00 committed by GitHub
commit cec3baeaa4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 56 additions and 7 deletions

View file

@ -1,7 +1,8 @@
<div class="blocks-container blockchain-blocks-container" *ngIf="(loadingBlocks$ | async) === false; else loadingBlocksTemplate"> <div class="blocks-container blockchain-blocks-container" *ngIf="(loadingBlocks$ | async) === false; else loadingBlocksTemplate">
<div *ngFor="let block of blocks; let i = index; trackBy: trackByBlocksFn" > <div *ngFor="let block of blocks; let i = index; trackBy: trackByBlocksFn" >
<div class="text-center bitcoin-block mined-block blockchain-blocks-{{ i }}" id="bitcoin-block-{{ block.height }}" [ngStyle]="blockStyles[i]" [class.blink-bg]="(specialBlocks[block.height] !== undefined)"> <div class="text-center bitcoin-block mined-block blockchain-blocks-{{ i }}" id="bitcoin-block-{{ block.height }}" [ngStyle]="blockStyles[i]" [class.blink-bg]="(specialBlocks[block.height] !== undefined)">
<a [routerLink]="['/block/' | relativeUrl, block.id]" [state]="{ data: { block: block } }" class="blockLink">&nbsp;</a> <a draggable="false" [routerLink]="['/block/' | relativeUrl, block.id]" [state]="{ data: { block: block } }"
class="blockLink" [ngClass]="{'disabled': (this.stateService.blockScrolling$ | async)}">&nbsp;</a>
<div class="block-height"> <div class="block-height">
<a [routerLink]="['/block/' | relativeUrl, block.id]" [state]="{ data: { block: block } }">{{ block.height }}</a> <a [routerLink]="['/block/' | relativeUrl, block.id]" [state]="{ data: { block: block } }">{{ block.height }}</a>
</div> </div>

View file

@ -15,6 +15,10 @@
text-decoration: none; text-decoration: none;
} }
.blockLink.disabled {
pointer-events: none;
}
.mined-block { .mined-block {
position: absolute; position: absolute;
top: 0px; top: 0px;

View file

@ -41,7 +41,7 @@ export class BlockchainBlocksComponent implements OnInit, OnDestroy {
}; };
constructor( constructor(
private stateService: StateService, public stateService: StateService,
private router: Router, private router: Router,
private cd: ChangeDetectorRef, private cd: ChangeDetectorRef,
) { } ) { }

View file

@ -18,6 +18,11 @@
.blockchain-wrapper { .blockchain-wrapper {
overflow: hidden; overflow: hidden;
height: 250px; height: 250px;
-webkit-user-select: none; /* Safari */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* IE10+/Edge */
user-select: none; /* Standard */
} }
.position-container { .position-container {

View file

@ -3,7 +3,8 @@
<div class="flashing"> <div class="flashing">
<ng-template ngFor let-projectedBlock [ngForOf]="mempoolBlocks$ | async" let-i="index" [ngForTrackBy]="trackByFn"> <ng-template ngFor let-projectedBlock [ngForOf]="mempoolBlocks$ | async" let-i="index" [ngForTrackBy]="trackByFn">
<div class="bitcoin-block text-center mempool-block" id="mempool-block-{{ i }}" [ngStyle]="mempoolBlockStyles[i]" [class.blink-bg]="projectedBlock.blink"> <div class="bitcoin-block text-center mempool-block" id="mempool-block-{{ i }}" [ngStyle]="mempoolBlockStyles[i]" [class.blink-bg]="projectedBlock.blink">
<a [routerLink]="['/mempool-block/' | relativeUrl, i]" class="blockLink">&nbsp;</a> <a draggable="false" [routerLink]="['/mempool-block/' | relativeUrl, i]"
class="blockLink" [ngClass]="{'disabled': (this.stateService.blockScrolling$ | async)}">&nbsp;</a>
<div class="block-body"> <div class="block-body">
<div class="fees"> <div class="fees">
~{{ projectedBlock.medianFee | number:feeRounding }} <span i18n="shared.sat-vbyte|sat/vB">sat/vB</span> ~{{ projectedBlock.medianFee | number:feeRounding }} <span i18n="shared.sat-vbyte|sat/vB">sat/vB</span>

View file

@ -117,6 +117,10 @@
z-index: 10; z-index: 10;
} }
.blockLink.disabled {
pointer-events: none;
}
.blockLink:hover { .blockLink:hover {
text-decoration: none; text-decoration: none;
} }

View file

@ -8,8 +8,11 @@
<div *ngIf="countdown > 0" class="warning-label">{{ eventName }} in {{ countdown | number }} block{{ countdown === 1 ? '' : 's' }}!</div> <div *ngIf="countdown > 0" class="warning-label">{{ eventName }} in {{ countdown | number }} block{{ countdown === 1 ? '' : 's' }}!</div>
<div id="blockchain-container" dir="ltr"> <div id="blockchain-container" dir="ltr" #blockchainContainer
<app-blockchain></app-blockchain> (mousedown)="onMouseDown($event)"
(dragstart)="onDragStart($event)"
>
<app-blockchain></app-blockchain>
</div> </div>
<router-outlet></router-outlet> <router-outlet></router-outlet>

View file

@ -1,8 +1,7 @@
import { Component, OnInit } from '@angular/core'; import { Component, ElementRef, HostListener, OnInit, ViewChild } from '@angular/core';
import { WebsocketService } from 'src/app/services/websocket.service'; import { WebsocketService } from 'src/app/services/websocket.service';
import { StateService } from 'src/app/services/state.service'; import { StateService } from 'src/app/services/state.service';
import { specialBlocks } from 'src/app/app.constants'; import { specialBlocks } from 'src/app/app.constants';
import { takeLast } from 'rxjs/operators';
@Component({ @Component({
selector: 'app-start', selector: 'app-start',
@ -16,6 +15,9 @@ export class StartComponent implements OnInit {
countdown = 0; countdown = 0;
specialEvent = false; specialEvent = false;
eventName = ''; eventName = '';
mouseDragStartX: number;
blockchainScrollLeftInit: number;
@ViewChild('blockchainContainer') blockchainContainer: ElementRef;
constructor( constructor(
private websocketService: WebsocketService, private websocketService: WebsocketService,
@ -50,4 +52,27 @@ export class StartComponent implements OnInit {
}); });
} }
onMouseDown(event: MouseEvent) {
this.mouseDragStartX = event.clientX;
this.blockchainScrollLeftInit = this.blockchainContainer.nativeElement.scrollLeft;
}
onDragStart(event: MouseEvent) { // Ignore Firefox annoying default drag behavior
event.preventDefault();
}
// We're catching the whole page event here because we still want to scroll blocks
// even if the mouse leave the blockchain blocks container. Same idea for mouseup below.
@HostListener('document:mousemove', ['$event'])
onMouseMove(event: MouseEvent): void {
if (this.mouseDragStartX != null) {
this.stateService.setBlockScrollingInProgress(true);
this.blockchainContainer.nativeElement.scrollLeft =
this.blockchainScrollLeftInit + this.mouseDragStartX - event.clientX
}
}
@HostListener('document:mouseup', [])
onMouseUp() {
this.mouseDragStartX = null;
this.stateService.setBlockScrollingInProgress(false);
}
} }

View file

@ -89,6 +89,8 @@ export class StateService {
markBlock$ = new ReplaySubject<MarkBlockState>(); markBlock$ = new ReplaySubject<MarkBlockState>();
keyNavigation$ = new Subject<KeyboardEvent>(); keyNavigation$ = new Subject<KeyboardEvent>();
blockScrolling$: Subject<boolean> = new Subject<boolean>();
constructor( constructor(
@Inject(PLATFORM_ID) private platformId: any, @Inject(PLATFORM_ID) private platformId: any,
private router: Router, private router: Router,
@ -176,4 +178,8 @@ export class StateService {
if (!prop) { return false; } if (!prop) { return false; }
return document[prop]; return document[prop];
} }
setBlockScrollingInProgress(value: boolean) {
this.blockScrolling$.next(value);
}
} }