Unverified Commit 58beffe9 authored by Flávio Fernandes's avatar Flávio Fernandes Committed by GitHub
Browse files

Extend the purchase page to support pagination (#701)

parent 6d9c1399
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -2142,6 +2142,10 @@
        "cursor": {
          "type": "string",
          "description": "The cursor to send when retrieving the next page, if any."
        },
        "prevCursor": {
          "type": "string",
          "description": "The cursor to send when retrieving the next page, if any."
        }
      },
      "description": "A list of validated purchases stored by Nakama."
+50 −40
Original line number Diff line number Diff line
@@ -3,6 +3,20 @@
  <h6 class="mr-2 d-inline font-weight-bold">Error while processing request: {{error}}</h6>
</ngb-alert>

<div class="row no-gutters mb-3">
  <div class="col d-flex justify-content-between no-gutters">
    <div class="col-md-9"></div>
    <div class="col-md-3 justify-content-end text-right">
      <div class="btn-group page-btns" role="group">
        <button type="button" class="btn btn-outline-secondary" (click)="loadData('')" [disabled]="purchases.length === 0"><img src="/static/svg/page-first.svg" alt="" width="20" height=""></button>
        <button type="button" class="btn btn-outline-secondary" (click)="loadData(prevCursor)" [disabled]="prevCursor === ''"><img src="/static/svg/page-prev.svg" alt="" width="20" height=""></button>
        <button type="button" class="btn btn-outline-secondary" (click)="loadData(nextCursor)" [disabled]="nextCursor === ''"><img src="/static/svg/page-next.svg" alt="" width="20" height=""></button>
      </div>
    </div>
  </div>
</div>

<div class="row no-gutters">
  <table class="table table-sm table-bordered table-hover">
    <thead class="thead-light">
    <tr>
@@ -42,8 +56,4 @@
    <tr *ngIf="purchases.length === 0"><td colspan="5" class="text-muted">No purchases were found.</td></tr>
    </tbody>
  </table>

<div *ngIf="nextCursor" class="col-12 text-center">
  <button (click)="loadOlderPurchases()" class="btn btn-outline-primary mt-3">Load more entries</button>
</div>
+8 −5
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ export class PurchasesComponent implements OnInit {
  public purchasesRowsOpen: boolean[] = [];
  public error = '';
  public nextCursor = '';
  public prevCursor = '';
  public userID: string;
  public readonly limit = 100;

@@ -39,21 +40,23 @@ export class PurchasesComponent implements OnInit {
  ngOnInit(): void {
    this.userID = this.route.parent.snapshot.paramMap.get('id');
    this.route.data.subscribe(data => {
      this.purchases.push(...data[0].validated_purchases);
      this.purchases = data[0].validated_purchases;
      this.nextCursor = data[0].cursor;
      this.prevCursor = data[0].prev_cursor;
    });
  }

  loadOlderPurchases(): void {
  loadData(cursor: string): void {
    this.consoleService.listPurchases(
      '',
      this.userID,
      this.limit,
      this.nextCursor,
      cursor,
    ).subscribe(res => {
      this.purchases.push(...res.validated_purchases);
      this.purchasesRowsOpen.push(...Array(res.validated_purchases.length).fill(false));
      this.purchases = res.validated_purchases;
      this.purchasesRowsOpen = [];
      this.nextCursor = res.cursor;
      this.prevCursor = res.prev_cursor;
    }, error => {
      this.error = error;
    });
+1 −0
Original line number Diff line number Diff line
@@ -517,6 +517,7 @@ export interface ApiNotification {
export interface ApiPurchaseList {
  validated_purchases?: ApiValidatedPurchase[]
  cursor?: string
  prev_cursor?: string
}

export interface ApiReadStorageObjectId {
+2 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ require (
	github.com/dop251/goja v0.0.0-20210406175830-1b11a6af686d
	github.com/glycerine/go-unsnap-stream v0.0.0-20190901134440-81cf024a9e0a // indirect
	github.com/gofrs/uuid v4.0.0+incompatible
	github.com/golang/protobuf v1.5.2 // indirect
	github.com/gorilla/handlers v1.5.1
	github.com/gorilla/mux v1.8.0
	github.com/gorilla/websocket v1.4.2
@@ -34,7 +35,7 @@ require (
	google.golang.org/genproto v0.0.0-20210224155714-063164c882e6
	google.golang.org/grpc v1.37.0
	google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0
	google.golang.org/protobuf v1.26.0
	google.golang.org/protobuf v1.27.1
	gopkg.in/natefinch/lumberjack.v2 v2.0.0-20190411184413-94d9e492cc53
	gopkg.in/yaml.v2 v2.4.0
)
Loading