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 align="right">
<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">&#x24e9; {{(item.cost/price)*100000000 | number: '1.0-0'}}</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/zecPrice)*100000000 | number: '1.0-0'}}</p>
</td>
</tr>
</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 { Observable } from 'rxjs';
import { Item } from '../item.model';
@ -19,6 +19,10 @@ import { ItemAddComponent } from '../item-add/item-add.component';
})
export class ItemListComponent implements OnInit{
@Input()
zecPrice: number = 1;
public items: Item[] = [];
owner: Owner = {
_id: '',
@ -45,10 +49,8 @@ export class ItemListComponent implements OnInit{
expiration: new Date(Date.now()).toISOString(),
viewkey: ''
};
public price: number = 1;
public ownerUpdate: Observable<Owner>;
public itemsUpdate: Observable<Item[]>;
public priceUpdate: Observable<number>;
constructor(
public itemService: ItemService,
@ -59,18 +61,13 @@ export class ItemListComponent implements OnInit{
) {
this.ownerUpdate = userService.ownerUpdate;
this.itemsUpdate = itemService.itemsUpdated;
this.priceUpdate = fullnodeService.priceUpdate;
this.ownerUpdate.subscribe((owner) => {
this.owner = owner;
fullnodeService.getPrice(this.owner.currency);
itemService.getItems(this.owner.address);
this.itemsUpdate.subscribe((items) => {
this.items = items;
});
});
this.priceUpdate.subscribe((price) => {
this.price = price;
});
}
ngOnInit(){

View File

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

View File

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