Browse Source

feat(client): migrate unit to input signal

pull/7265/head
KenTandrian 1 week ago
parent
commit
dfc6045a03
  1. 2
      apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html
  2. 58
      apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts

2
apps/client/src/app/components/portfolio-performance/portfolio-performance.component.html

@ -29,7 +29,7 @@
<span #value id="value"></span> <span #value id="value"></span>
</div> </div>
<div class="currency-container flex-grow-1 px-1"> <div class="currency-container flex-grow-1 px-1">
{{ unit }} {{ unit() }}
</div> </div>
</div> </div>
@if (showDetails()) { @if (showDetails()) {

58
apps/client/src/app/components/portfolio-performance/portfolio-performance.component.ts

@ -14,10 +14,9 @@ import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
ElementRef, ElementRef,
effect,
inject, inject,
input, input,
Input,
OnChanges,
viewChild viewChild
} from '@angular/core'; } from '@angular/core';
import { IonIcon } from '@ionic/angular/standalone'; import { IonIcon } from '@ionic/angular/standalone';
@ -34,9 +33,7 @@ import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
styleUrls: ['./portfolio-performance.component.scss'], styleUrls: ['./portfolio-performance.component.scss'],
templateUrl: './portfolio-performance.component.html' templateUrl: './portfolio-performance.component.html'
}) })
export class GfPortfolioPerformanceComponent implements OnChanges { export class GfPortfolioPerformanceComponent {
@Input() unit: string;
public readonly errors = input<ResponseError['errors']>(); public readonly errors = input<ResponseError['errors']>();
public readonly isLoading = input<boolean>(); public readonly isLoading = input<boolean>();
public readonly locale = input<string>(getLocale()); public readonly locale = input<string>(getLocale());
@ -47,6 +44,7 @@ export class GfPortfolioPerformanceComponent implements OnChanges {
} }
}); });
public readonly showDetails = input<boolean>(false); public readonly showDetails = input<boolean>(false);
public readonly unit = input.required<string>();
private readonly value = private readonly value =
viewChild.required<ElementRef<HTMLSpanElement>>('value'); viewChild.required<ElementRef<HTMLSpanElement>>('value');
@ -55,36 +53,36 @@ export class GfPortfolioPerformanceComponent implements OnChanges {
public constructor() { public constructor() {
addIcons({ timeOutline }); addIcons({ timeOutline });
}
public ngOnChanges() { effect(() => {
if (this.isLoading()) { if (this.isLoading()) {
if (this.value().nativeElement) { if (this.value().nativeElement) {
this.value().nativeElement.innerHTML = ''; this.value().nativeElement.innerHTML = '';
} }
} else { } else {
if (isNumber(this.performance().currentValueInBaseCurrency)) { if (isNumber(this.performance().currentValueInBaseCurrency)) {
new CountUp('value', this.performance().currentValueInBaseCurrency, { new CountUp('value', this.performance().currentValueInBaseCurrency, {
decimal: getNumberFormatDecimal(this.locale()),
decimalPlaces: this.precision(),
duration: 1,
separator: getNumberFormatGroup(this.locale())
}).start();
} else if (this.showDetails() === false) {
new CountUp(
'value',
this.performance().netPerformancePercentageWithCurrencyEffect * 100,
{
decimal: getNumberFormatDecimal(this.locale()), decimal: getNumberFormatDecimal(this.locale()),
decimalPlaces: 2, decimalPlaces: this.precision(),
duration: 1, duration: 1,
separator: getNumberFormatGroup(this.locale()) separator: getNumberFormatGroup(this.locale())
} }).start();
).start(); } else if (this.showDetails() === false) {
} else { new CountUp(
this.value().nativeElement.innerHTML = '*****'; 'value',
this.performance().netPerformancePercentageWithCurrencyEffect * 100,
{
decimal: getNumberFormatDecimal(this.locale()),
decimalPlaces: 2,
duration: 1,
separator: getNumberFormatGroup(this.locale())
}
).start();
} else {
this.value().nativeElement.innerHTML = '*****';
}
} }
} });
} }
protected onShowErrors() { protected onShowErrors() {

Loading…
Cancel
Save