From 6f03a52b55768973444fcdfed75d74a78624c7f4 Mon Sep 17 00:00:00 2001 From: Thomas Kaul <4159106+dtslvr@users.noreply.github.com> Date: Tue, 3 Dec 2024 20:44:18 +0100 Subject: [PATCH] Refactoring --- .../admin-market-data.component.ts | 2 +- .../asset-profile-dialog.component.ts | 14 +++++------ .../asset-profile-dialog.html | 1 - .../asset-profile-dialog.module.ts | 2 +- .../interfaces/interfaces.ts | 0 .../market-data-detail-dialog.component.ts | 2 +- .../market-data-detail.component.ts | 23 +++++++++++-------- 7 files changed, 22 insertions(+), 22 deletions(-) rename apps/client/src/app/components/admin-market-data/{ => asset-profile-dialog}/interfaces/interfaces.ts (100%) diff --git a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts b/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts index 696174699..5eb869694 100644 --- a/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts +++ b/apps/client/src/app/components/admin-market-data/admin-market-data.component.ts @@ -39,9 +39,9 @@ import { distinctUntilChanged, switchMap, takeUntil } from 'rxjs/operators'; import { AdminMarketDataService } from './admin-market-data.service'; import { AssetProfileDialog } from './asset-profile-dialog/asset-profile-dialog.component'; +import { AssetProfileDialogParams } from './asset-profile-dialog/interfaces/interfaces'; import { CreateAssetProfileDialog } from './create-asset-profile-dialog/create-asset-profile-dialog.component'; import { CreateAssetProfileDialogParams } from './create-asset-profile-dialog/interfaces/interfaces'; -import { AssetProfileDialogParams } from './interfaces/interfaces'; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts index 322ed41c8..165c63672 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.component.ts @@ -10,8 +10,8 @@ import { DATE_FORMAT } from '@ghostfolio/common/helper'; import { AdminMarketDataDetails, AssetProfileIdentifier, - User, - LineChartItem + LineChartItem, + User } from '@ghostfolio/common/interfaces'; import { translate } from '@ghostfolio/ui/i18n'; @@ -35,7 +35,7 @@ import { format } from 'date-fns'; import { EMPTY, Subject } from 'rxjs'; import { catchError, takeUntil } from 'rxjs/operators'; -import { AssetProfileDialogParams } from '../interfaces/interfaces'; +import { AssetProfileDialogParams } from './interfaces/interfaces'; @Component({ host: { class: 'd-flex flex-column h-100' }, @@ -118,6 +118,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit { this.user = state.user; } }); + this.adminService .fetchAdminMarketDataBySymbol({ dataSource: this.data.dataSource, @@ -130,10 +131,10 @@ export class AssetProfileDialog implements OnDestroy, OnInit { this.assetProfileClass = translate(this.assetProfile?.assetClass); this.assetProfileSubClass = translate(this.assetProfile?.assetSubClass); this.countries = {}; + this.isBenchmark = this.benchmarks.some(({ id }) => { return id === this.assetProfile.id; }); - this.marketDataDetails = marketData; this.historicalDataItems = this.marketDataDetails.map( ({ date, marketPrice }) => { @@ -144,6 +145,7 @@ export class AssetProfileDialog implements OnDestroy, OnInit { } ); + this.marketDataDetails = marketData; this.sectors = {}; if (this.assetProfile?.countries?.length > 0) { @@ -225,10 +227,6 @@ export class AssetProfileDialog implements OnDestroy, OnInit { } } - public onImportHistoricalDataChanged() { - this.initialize(); - } - public onSetBenchmark({ dataSource, symbol }: AssetProfileIdentifier) { this.dataService .postBenchmark({ dataSource, symbol }) diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html index 65f7d1059..b33371bfb 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.html @@ -87,7 +87,6 @@ [marketData]="marketDataDetails" [symbol]="data.symbol" [user]="user" - (historicalDataUpdated)="onImportHistoricalDataChanged()" (marketDataChanged)="onMarketDataChanged($event)" /> diff --git a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts index ceea421a3..74dcdaef3 100644 --- a/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts +++ b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/asset-profile-dialog.module.ts @@ -23,12 +23,12 @@ import { AssetProfileDialog } from './asset-profile-dialog.component'; @NgModule({ declarations: [AssetProfileDialog], imports: [ - GfMarketDataDetailComponent, CommonModule, FormsModule, GfAssetProfileIconComponent, GfCurrencySelectorComponent, GfLineChartComponent, + GfMarketDataDetailComponent, GfPortfolioProportionChartComponent, GfValueComponent, MatButtonModule, diff --git a/apps/client/src/app/components/admin-market-data/interfaces/interfaces.ts b/apps/client/src/app/components/admin-market-data/asset-profile-dialog/interfaces/interfaces.ts similarity index 100% rename from apps/client/src/app/components/admin-market-data/interfaces/interfaces.ts rename to apps/client/src/app/components/admin-market-data/asset-profile-dialog/interfaces/interfaces.ts diff --git a/libs/ui/src/lib/market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts b/libs/ui/src/lib/market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts index 095a4ef76..96e52d461 100644 --- a/libs/ui/src/lib/market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts +++ b/libs/ui/src/lib/market-data-detail/market-data-detail-dialog/market-data-detail-dialog.component.ts @@ -25,6 +25,7 @@ import { Subject, takeUntil } from 'rxjs'; import { MarketDataDetailDialogParams } from './interfaces/interfaces'; @Component({ + changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'h-100' }, imports: [ CommonModule, @@ -37,7 +38,6 @@ import { MarketDataDetailDialogParams } from './interfaces/interfaces'; ReactiveFormsModule ], selector: 'gf-market-data-detail-dialog', - changeDetection: ChangeDetectionStrategy.OnPush, schemas: [CUSTOM_ELEMENTS_SCHEMA], standalone: true, styleUrls: ['./market-data-detail-dialog.scss'], diff --git a/libs/ui/src/lib/market-data-detail/market-data-detail.component.ts b/libs/ui/src/lib/market-data-detail/market-data-detail.component.ts index 52bd895a7..28a4d671e 100644 --- a/libs/ui/src/lib/market-data-detail/market-data-detail.component.ts +++ b/libs/ui/src/lib/market-data-detail/market-data-detail.component.ts @@ -14,6 +14,7 @@ import { EventEmitter, Input, OnChanges, + OnDestroy, OnInit, Output } from '@angular/core'; @@ -53,7 +54,9 @@ import { MarketDataDetailDialogComponent } from './market-data-detail-dialog/mar styleUrls: ['./market-data-detail.component.scss'], templateUrl: './market-data-detail.component.html' }) -export class GfMarketDataDetailComponent implements OnChanges, OnInit { +export class GfMarketDataDetailComponent + implements OnChanges, OnDestroy, OnInit +{ @Input() currency: string; @Input() dataSource: DataSource; @Input() dateOfFirstActivity: string; @@ -63,7 +66,6 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit { @Input() user: User; @Output() marketDataChanged = new EventEmitter(); - @Output() historicalDataUpdated = new EventEmitter(); public days = Array(31); public defaultDateFormat: string; @@ -90,8 +92,8 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit { public constructor( private adminService: AdminService, private deviceService: DeviceDetectorService, - private formBuilder: FormBuilder, private dialog: MatDialog, + private formBuilder: FormBuilder, private snackBar: MatSnackBar ) { this.deviceType = this.deviceService.getDeviceInfo().deviceType; @@ -215,7 +217,7 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit { .afterClosed() .pipe(takeUntil(this.unsubscribeSubject)) .subscribe(({ withRefresh } = { withRefresh: false }) => { - this.marketDataChanged.next(withRefresh); + this.marketDataChanged.emit(withRefresh); }); } @@ -249,8 +251,9 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit { takeUntil(this.unsubscribeSubject) ) .subscribe(() => { - this.historicalDataUpdated.emit(); this.initializeHistoricalDataForm(); + + this.marketDataChanged.emit(true); }); } catch { this.snackBar.open( @@ -261,6 +264,11 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit { } } + public ngOnDestroy() { + this.unsubscribeSubject.next(); + this.unsubscribeSubject.complete(); + } + private initializeHistoricalDataForm() { this.historicalDataForm.setValue({ historicalData: { @@ -268,9 +276,4 @@ export class GfMarketDataDetailComponent implements OnChanges, OnInit { } }); } - - public ngOnDestroy() { - this.unsubscribeSubject.next(); - this.unsubscribeSubject.complete(); - } }