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>
</div>
<div class="currency-container flex-grow-1 px-1">
{{ unit }}
{{ unit() }}
</div>
</div>
@if (showDetails()) {

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

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

Loading…
Cancel
Save