Browse Source

Refactoring

pull/2575/head
Thomas 2 years ago
parent
commit
7ad2de0d25
  1. 1
      apps/client/src/app/components/home-market/home-market.html
  2. 8
      libs/ui/src/lib/benchmark/benchmark.component.html
  3. 46
      libs/ui/src/lib/benchmark/benchmark.component.ts

1
apps/client/src/app/components/home-market/home-market.html

@ -31,6 +31,7 @@
<gf-benchmark
[benchmarks]="benchmarks"
[locale]="user?.settings?.locale"
[user]="user"
></gf-benchmark>
<ngx-skeleton-loader
*ngIf="isLoading"

8
libs/ui/src/lib/benchmark/benchmark.component.html

@ -20,9 +20,9 @@
*ngIf="element?.trend50d !== 'UNKNOWN'"
[value]="
element?.trend50d === 'UP'
? 1
? 0.001
: element?.trend50d === 'DOWN'
? -1
? -0.001
: 0
"
></gf-trend-indicator>
@ -44,9 +44,9 @@
*ngIf="element?.trend200d !== 'UNKNOWN'"
[value]="
element?.trend200d === 'UP'
? 1
? 0.001
: element?.trend200d === 'DOWN'
? -1
? -0.001
: 0
"
></gf-trend-indicator>

46
libs/ui/src/lib/benchmark/benchmark.component.ts

@ -1,16 +1,11 @@
import {
ChangeDetectionStrategy,
ChangeDetectorRef,
Component,
Input,
OnChanges
} from '@angular/core';
import { UserService } from '@ghostfolio/client/services/user/user.service';
import { locale } from '@ghostfolio/common/config';
import { resolveMarketCondition } from '@ghostfolio/common/helper';
import { Benchmark, User } from '@ghostfolio/common/interfaces';
import { without } from 'lodash';
import { Subject, takeUntil } from 'rxjs';
@Component({
selector: 'gf-benchmark',
@ -21,42 +16,23 @@ import { Subject, takeUntil } from 'rxjs';
export class BenchmarkComponent implements OnChanges {
@Input() benchmarks: Benchmark[];
@Input() locale: string;
@Input() user: User;
public displayedColumns = ['name', 'date', 'change', 'marketCondition'];
public resolveMarketCondition = resolveMarketCondition;
public user: User;
private unsubscribeSubject = new Subject<void>();
public constructor(
private changeDetectorRef: ChangeDetectorRef,
private userService: UserService
) {
this.userService.stateChanged
.pipe(takeUntil(this.unsubscribeSubject))
.subscribe((state) => {
if (state?.user) {
this.user = state.user;
if (this.user?.settings?.isExperimentalFeatures) {
this.displayedColumns = [
'name',
'trend50d',
'trend200d',
'date',
'change',
'marketCondition'
];
}
this.changeDetectorRef.markForCheck();
}
});
}
public constructor() {}
public ngOnChanges() {
if (!this.locale) {
this.locale = locale;
if (this.user?.settings?.isExperimentalFeatures) {
this.displayedColumns = [
'name',
'trend50d',
'trend200d',
'date',
'change',
'marketCondition'
];
}
}
}

Loading…
Cancel
Save