Skip to content

Commit

Permalink
web-ui: added color effect on newest blocks (fixes wiringbits#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
mario128mex committed Jun 17, 2018
1 parent 5008c73 commit 9f7ab96
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.latest-block {
animation: blinker 1s linear;
}

@keyframes blinker {
50% {
background-color: #D4FFD4;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ <h4>{{'message.loadingLatestBlocks' | translate}}</h4>
</thead>

<tbody>
<tr *ngFor="let item of blocks">
<tr *ngFor="let item of blocks; let i = index" [ngClass]="{ 'latest-block': isBlockRecent(i) }">
<td>
<a routerLink="/blocks/{{item.hash}}">{{item.height}}</a>
</td>
Expand Down
27 changes: 27 additions & 0 deletions web-ui/src/app/components/latest-blocks/latest-blocks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { ErrorService } from '../../services/error.service';
export class LatestBlocksComponent implements OnInit, OnDestroy {

blocks: Block[];
private totalNewestBlocks: number;
private latestBlock: Block;
private subscription$: Subscription;

constructor(
Expand Down Expand Up @@ -70,9 +72,30 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
}

private onBlockRetrieved(response: Block[]) {
this.countNewestBlocks(response);
this.latestBlock = response[0];
this.blocks = response;
}

private countNewestBlocks(newBlocks: Block[]) {
if (!this.blocks) {
return;
}

const lastestBlockHash: string = this.latestBlock.hash;
let totalNewBlocks = 0;

for (let i = 0; i < newBlocks.length; i++) {
if (newBlocks[i].hash === lastestBlockHash) {
break;
}

totalNewBlocks++;
}

this.totalNewestBlocks = totalNewBlocks;
}

private onError(response: any) {
this.errorService.renderServerErrors(null, response);
}
Expand All @@ -92,4 +115,8 @@ export class LatestBlocksComponent implements OnInit, OnDestroy {
age(block: Block): string {
return '';
}

isBlockRecent(index: number): boolean {
return index < this.totalNewestBlocks;
}
}

0 comments on commit 9f7ab96

Please sign in to comment.