Add pagination history to bisq transactions and blocks page.

This commit is contained in:
softsimon 2020-08-07 13:11:55 +07:00
parent 01b3407a9c
commit fea79f2ff4
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7
7 changed files with 42 additions and 14 deletions

View File

@ -27,7 +27,7 @@
<br> <br>
<ngb-pagination [size]="paginationSize" [collectionSize]="blocks.value ? blocks.value[1] : 0" [rotate]="true" [pageSize]="itemsPerPage" [(page)]="page" (pageChange)="pageChange(page)" [maxSize]="paginationMaxSize" [boundaryLinks]="true"></ngb-pagination> <ngb-pagination *ngIf="blocks.value" [size]="paginationSize" [collectionSize]="blocks.value[1]" [rotate]="true" [pageSize]="itemsPerPage" [(page)]="page" (pageChange)="pageChange(page)" [maxSize]="paginationMaxSize" [boundaryLinks]="true"></ngb-pagination>
</ng-container> </ng-container>
</div> </div>

View File

@ -4,6 +4,7 @@ import { switchMap, map } from 'rxjs/operators';
import { Subject, Observable, of, merge } from 'rxjs'; import { Subject, Observable, of, merge } from 'rxjs';
import { BisqBlock, BisqOutput, BisqTransaction } from '../bisq.interfaces'; import { BisqBlock, BisqOutput, BisqTransaction } from '../bisq.interfaces';
import { SeoService } from 'src/app/services/seo.service'; import { SeoService } from 'src/app/services/seo.service';
import { ActivatedRoute, Router } from '@angular/router';
@Component({ @Component({
selector: 'app-bisq-blocks', selector: 'app-bisq-blocks',
@ -23,11 +24,11 @@ export class BisqBlocksComponent implements OnInit {
paginationSize: 'sm' | 'lg' = 'md'; paginationSize: 'sm' | 'lg' = 'md';
paginationMaxSize = 10; paginationMaxSize = 10;
pageSubject$ = new Subject<number>();
constructor( constructor(
private bisqApiService: BisqApiService, private bisqApiService: BisqApiService,
private seoService: SeoService, private seoService: SeoService,
private route: ActivatedRoute,
private router: Router,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
@ -39,8 +40,15 @@ export class BisqBlocksComponent implements OnInit {
this.paginationMaxSize = 3; this.paginationMaxSize = 3;
} }
this.blocks$ = merge(of(1), this.pageSubject$) this.blocks$ = this.route.queryParams
.pipe( .pipe(
map((queryParams) => {
if (queryParams.page) {
this.page = parseInt(queryParams.page, 10);
return parseInt(queryParams.page, 10);
}
return 1;
}),
switchMap((page) => this.bisqApiService.listBlocks$((page - 1) * this.itemsPerPage, this.itemsPerPage)), switchMap((page) => this.bisqApiService.listBlocks$((page - 1) * this.itemsPerPage, this.itemsPerPage)),
map((response) => [response.body, parseInt(response.headers.get('x-total-count'), 10)]), map((response) => [response.body, parseInt(response.headers.get('x-total-count'), 10)]),
); );
@ -57,6 +65,10 @@ export class BisqBlocksComponent implements OnInit {
} }
pageChange(page: number) { pageChange(page: number) {
this.pageSubject$.next(page); this.router.navigate([], {
queryParams: { page: page },
replaceUrl: true,
queryParamsHandling: 'merge',
});
} }
} }

View File

@ -155,7 +155,7 @@
<div class="clearfix"></div> <div class="clearfix"></div>
<div class="text-center"> <div class="text-center">
Error loading transaction Error loading Bisq transaction
<br><br> <br><br>
<i>{{ error.status }}: {{ error.statusText }}</i> <i>{{ error.status }}: {{ error.statusText }}</i>
</div> </div>

View File

@ -94,7 +94,7 @@
<br> <br>
<ngb-pagination [size]="paginationSize" [collectionSize]="transactions.value ? transactions.value[1] : 0" [rotate]="true" [pageSize]="itemsPerPage" [(page)]="page" (pageChange)="pageChange(page)" [maxSize]="paginationMaxSize" [boundaryLinks]="true"></ngb-pagination> <ngb-pagination *ngIf="transactions.value" [size]="paginationSize" [collectionSize]="transactions.value[1]" [rotate]="true" [pageSize]="itemsPerPage" [(page)]="page" (pageChange)="pageChange(page)" [maxSize]="paginationMaxSize" [boundaryLinks]="true"></ngb-pagination>
</ng-container> </ng-container>
</div> </div>

View File

@ -1,10 +1,11 @@
import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core'; import { Component, OnInit, ChangeDetectionStrategy } from '@angular/core';
import { BisqTransaction, BisqOutput } from '../bisq.interfaces'; import { BisqTransaction, BisqOutput } from '../bisq.interfaces';
import { Subject, merge, Observable, of } from 'rxjs'; import { Subject, merge, Observable } from 'rxjs';
import { switchMap, map } from 'rxjs/operators'; import { switchMap, map } from 'rxjs/operators';
import { BisqApiService } from '../bisq-api.service'; import { BisqApiService } from '../bisq-api.service';
import { SeoService } from 'src/app/services/seo.service'; import { SeoService } from 'src/app/services/seo.service';
import { FormGroup, FormBuilder } from '@angular/forms'; import { FormGroup, FormBuilder } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
@Component({ @Component({
selector: 'app-bisq-transactions', selector: 'app-bisq-transactions',
@ -20,7 +21,6 @@ export class BisqTransactionsComponent implements OnInit {
fiveItemsPxSize = 250; fiveItemsPxSize = 250;
isLoading = true; isLoading = true;
loadingItems: number[]; loadingItems: number[];
pageSubject$ = new Subject<number>();
radioGroupForm: FormGroup; radioGroupForm: FormGroup;
types: string[] = []; types: string[] = [];
@ -32,6 +32,8 @@ export class BisqTransactionsComponent implements OnInit {
private bisqApiService: BisqApiService, private bisqApiService: BisqApiService,
private seoService: SeoService, private seoService: SeoService,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private route: ActivatedRoute,
private router: Router,
) { } ) { }
ngOnInit(): void { ngOnInit(): void {
@ -63,8 +65,16 @@ export class BisqTransactionsComponent implements OnInit {
} }
this.transactions$ = merge( this.transactions$ = merge(
of(1), this.route.queryParams
this.pageSubject$, .pipe(
map((queryParams) => {
if (queryParams.page) {
this.page = parseInt(queryParams.page, 10);
return parseInt(queryParams.page, 10);
}
return 1;
})
),
this.radioGroupForm.valueChanges this.radioGroupForm.valueChanges
.pipe( .pipe(
map((data) => { map((data) => {
@ -75,6 +85,9 @@ export class BisqTransactionsComponent implements OnInit {
} }
} }
this.types = types; this.types = types;
if (this.page !== 1) {
this.pageChange(1);
}
return 1; return 1;
}) })
) )
@ -86,7 +99,11 @@ export class BisqTransactionsComponent implements OnInit {
} }
pageChange(page: number) { pageChange(page: number) {
this.pageSubject$.next(page); this.router.navigate([], {
queryParams: { page: page },
replaceUrl: true,
queryParamsHandling: 'merge',
});
} }
calculateTotalOutput(outputs: BisqOutput[]): number { calculateTotalOutput(outputs: BisqOutput[]): number {

View File

@ -1,7 +1,6 @@
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { AboutComponent } from '../components/about/about.component'; import { AboutComponent } from '../components/about/about.component';
import { AddressComponent } from '../components/address/address.component';
import { BisqTransactionsComponent } from './bisq-transactions/bisq-transactions.component'; import { BisqTransactionsComponent } from './bisq-transactions/bisq-transactions.component';
import { BisqTransactionComponent } from './bisq-transaction/bisq-transaction.component'; import { BisqTransactionComponent } from './bisq-transaction/bisq-transaction.component';
import { BisqBlockComponent } from './bisq-block/bisq-block.component'; import { BisqBlockComponent } from './bisq-block/bisq-block.component';

View File

@ -53,7 +53,7 @@ export class StateService {
} }
setNetworkBasedonUrl(url: string) { setNetworkBasedonUrl(url: string) {
switch (url.split('/')[1]) { switch (url.split(/\/|\?|#/)[1]) {
case 'liquid': case 'liquid':
if (this.network !== 'liquid') { if (this.network !== 'liquid') {
this.network = 'liquid'; this.network = 'liquid';