Refactor item list to reduce server calls

This commit is contained in:
Rene Vergara 2022-07-14 14:04:04 -05:00
parent 4fe5857383
commit 8e09842f83
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
4 changed files with 14 additions and 11 deletions

View file

@ -6,8 +6,8 @@
<td>{{item.name}}</td> <td>{{item.name}}</td>
<td align="right"> <td align="right">
<p class="price">{{item.cost | currency: getCurrency() }}</p> <p class="price">{{item.cost | currency: getCurrency() }}</p>
<p class="price" *ngIf="!owner.zats"><img class="icon" src="/assets/spartan-zec.png" width="12px" />{{(item.cost/price) | number: '1.0-6'}}</p> <p class="price" *ngIf="!owner.zats"><img class="icon" src="/assets/spartan-zec.png" width="12px" />{{(item.cost/zecPrice) | number: '1.0-6'}}</p>
<p class="price" *ngIf="owner.zats">&#x24e9; {{(item.cost/price)*100000000 | number: '1.0-0'}}</p> <p class="price" *ngIf="owner.zats">&#x24e9; {{(item.cost/zecPrice)*100000000 | number: '1.0-0'}}</p>
</td> </td>
</tr> </tr>
</table> </table>

View file

@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { MatDialog, MatDialogConfig} from '@angular/material/dialog'; import { MatDialog, MatDialogConfig} from '@angular/material/dialog';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { Item } from '../item.model'; import { Item } from '../item.model';
@ -19,6 +19,10 @@ import { ItemAddComponent } from '../item-add/item-add.component';
}) })
export class ItemListComponent implements OnInit{ export class ItemListComponent implements OnInit{
@Input()
zecPrice: number = 1;
public items: Item[] = []; public items: Item[] = [];
owner: Owner = { owner: Owner = {
_id: '', _id: '',
@ -45,10 +49,8 @@ export class ItemListComponent implements OnInit{
expiration: new Date(Date.now()).toISOString(), expiration: new Date(Date.now()).toISOString(),
viewkey: '' viewkey: ''
}; };
public price: number = 1;
public ownerUpdate: Observable<Owner>; public ownerUpdate: Observable<Owner>;
public itemsUpdate: Observable<Item[]>; public itemsUpdate: Observable<Item[]>;
public priceUpdate: Observable<number>;
constructor( constructor(
public itemService: ItemService, public itemService: ItemService,
@ -59,18 +61,13 @@ export class ItemListComponent implements OnInit{
) { ) {
this.ownerUpdate = userService.ownerUpdate; this.ownerUpdate = userService.ownerUpdate;
this.itemsUpdate = itemService.itemsUpdated; this.itemsUpdate = itemService.itemsUpdated;
this.priceUpdate = fullnodeService.priceUpdate;
this.ownerUpdate.subscribe((owner) => { this.ownerUpdate.subscribe((owner) => {
this.owner = owner; this.owner = owner;
fullnodeService.getPrice(this.owner.currency);
itemService.getItems(this.owner.address); itemService.getItems(this.owner.address);
this.itemsUpdate.subscribe((items) => { this.itemsUpdate.subscribe((items) => {
this.items = items; this.items = items;
}); });
}); });
this.priceUpdate.subscribe((price) => {
this.price = price;
});
} }
ngOnInit(){ ngOnInit(){

View file

@ -14,7 +14,7 @@
</div> </div>
<div *ngIf="orientation"> <div *ngIf="orientation">
<app-order></app-order> <app-order></app-order>
<app-item-list></app-item-list> <app-item-list [zecPrice]="price"></app-item-list>
</div> </div>
<div *ngIf="!orientation" align="center"> <div *ngIf="!orientation" align="center">
<table cellspacing="0" width="75%"> <table cellspacing="0" width="75%">

View file

@ -52,9 +52,11 @@ export class ViewerComponent implements OnInit {
expiration: new Date(Date.now()).toISOString(), expiration: new Date(Date.now()).toISOString(),
viewkey: '' viewkey: ''
}; };
public price: number = 1;
public addrUpdate: Observable<string>; public addrUpdate: Observable<string>;
public ownerUpdate: Observable<Owner>; public ownerUpdate: Observable<Owner>;
public userUpdate: Observable<User>; public userUpdate: Observable<User>;
public priceUpdate: Observable<number>;
orientation: boolean = false; orientation: boolean = false;
constructor( constructor(
@ -65,6 +67,7 @@ export class ViewerComponent implements OnInit {
){ ){
this.addrUpdate = fullnodeService.addrUpdate; this.addrUpdate = fullnodeService.addrUpdate;
this.ownerUpdate = userService.ownerUpdate; this.ownerUpdate = userService.ownerUpdate;
this.priceUpdate = fullnodeService.priceUpdate;
this.ownerUpdate.subscribe((owner) => { this.ownerUpdate.subscribe((owner) => {
this.owner = owner; this.owner = owner;
}); });
@ -72,6 +75,9 @@ export class ViewerComponent implements OnInit {
this.userUpdate.subscribe((user) => { this.userUpdate.subscribe((user) => {
this.user = user; this.user = user;
}); });
this.priceUpdate.subscribe((price) => {
this.price = price;
});
} }
ngOnInit(){ ngOnInit(){