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 <gf-benchmark
[benchmarks]="benchmarks" [benchmarks]="benchmarks"
[locale]="user?.settings?.locale" [locale]="user?.settings?.locale"
[user]="user"
></gf-benchmark> ></gf-benchmark>
<ngx-skeleton-loader <ngx-skeleton-loader
*ngIf="isLoading" *ngIf="isLoading"

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

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

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

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

Loading…
Cancel
Save