diff --git a/CHANGELOG.md b/CHANGELOG.md index a3714bcdd..ad6854433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Extended the toggle component to support a disabled state - Extended the toggle component to support icons +- Reused the toggle component on the portfolio holdings page ## 3.46.0 - 2026-08-09 diff --git a/apps/client/src/app/components/home-holdings/home-holdings.component.ts b/apps/client/src/app/components/home-holdings/home-holdings.component.ts index 2a06f47ab..45dcd1a97 100644 --- a/apps/client/src/app/components/home-holdings/home-holdings.component.ts +++ b/apps/client/src/app/components/home-holdings/home-holdings.component.ts @@ -27,11 +27,8 @@ import { OnInit } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; -import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms'; import { MatButtonModule } from '@angular/material/button'; -import { MatButtonToggleModule } from '@angular/material/button-toggle'; import { Router, RouterModule } from '@angular/router'; -import { IonIcon } from '@ionic/angular/standalone'; import { addIcons } from 'ionicons'; import { gridOutline, reorderFourOutline } from 'ionicons/icons'; import { DeviceDetectorService } from 'ngx-device-detector'; @@ -39,14 +36,10 @@ import { DeviceDetectorService } from 'ngx-device-detector'; @Component({ changeDetection: ChangeDetectionStrategy.OnPush, imports: [ - FormsModule, GfHoldingsTableComponent, GfToggleComponent, GfTreemapChartComponent, - IonIcon, MatButtonModule, - MatButtonToggleModule, - ReactiveFormsModule, RouterModule ], schemas: [CUSTOM_ELEMENTS_SCHEMA], @@ -62,17 +55,29 @@ export class GfHomeHoldingsComponent implements OnInit { protected hasPermissionToAccessHoldingsChart: boolean; protected hasPermissionToCreateActivity: boolean; protected holdings: PortfolioPosition[] | undefined; + protected holdingsViewMode: HoldingsViewMode = + GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE; + protected readonly holdingsViewModeOptions: ToggleOption[] = [ + { + iconName: 'reorder-four-outline', + title: $localize`Table`, + value: 'TABLE' + }, + { + iconName: 'grid-outline', + title: $localize`Chart`, + value: 'CHART' + } + ]; protected holdingType: HoldingType = 'ACTIVE'; protected readonly holdingTypeOptions: ToggleOption[] = [ { label: $localize`Active`, value: 'ACTIVE' }, { label: $localize`Closed`, value: 'CLOSED' } ]; + protected isHoldingsViewModeToggleDisabled = true; protected readonly routerLinkPortfolioActivities = internalRoutes.portfolio.subRoutes.activities.routerLink; protected user: User; - protected readonly viewModeFormControl = new FormControl( - GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE - ); private readonly changeDetectorRef = inject(ChangeDetectorRef); private readonly dataService = inject(DataService); @@ -121,26 +126,22 @@ export class GfHomeHoldingsComponent implements OnInit { this.changeDetectorRef.markForCheck(); }); + } - this.viewModeFormControl.valueChanges - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe((holdingsViewMode) => { - if (!holdingsViewMode) { - return; - } + protected onChangeHoldingsViewMode(aHoldingsViewMode: HoldingsViewMode) { + this.holdingsViewMode = aHoldingsViewMode; - this.dataService - .putUserSetting({ holdingsViewMode }) + this.dataService + .putUserSetting({ holdingsViewMode: aHoldingsViewMode }) + .pipe(takeUntilDestroyed(this.destroyRef)) + .subscribe(() => { + this.userService + .get(true) .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe(() => { - this.userService - .get(true) - .pipe(takeUntilDestroyed(this.destroyRef)) - .subscribe((user) => { - this.user = user; - - this.changeDetectorRef.markForCheck(); - }); + .subscribe((user) => { + this.user = user; + + this.changeDetectorRef.markForCheck(); }); }); } @@ -173,26 +174,22 @@ export class GfHomeHoldingsComponent implements OnInit { } private initialize() { - this.viewModeFormControl.disable({ emitEvent: false }); + this.isHoldingsViewModeToggleDisabled = true; if ( this.hasPermissionToAccessHoldingsChart && this.holdingType === 'ACTIVE' ) { - this.viewModeFormControl.enable({ emitEvent: false }); + this.isHoldingsViewModeToggleDisabled = false; - this.viewModeFormControl.setValue( + this.holdingsViewMode = this.deviceType === 'mobile' ? GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE : (this.user?.settings?.holdingsViewMode ?? - GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE), - { emitEvent: false } - ); - } else if (this.holdingType === 'CLOSED') { - this.viewModeFormControl.setValue( - GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE, - { emitEvent: false } - ); + GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE); + } else { + this.holdingsViewMode = + GfHomeHoldingsComponent.DEFAULT_HOLDINGS_VIEW_MODE; } this.holdings = undefined; diff --git a/apps/client/src/app/components/home-holdings/home-holdings.html b/apps/client/src/app/components/home-holdings/home-holdings.html index c44df40b3..d3b24e7af 100644 --- a/apps/client/src/app/components/home-holdings/home-holdings.html +++ b/apps/client/src/app/components/home-holdings/home-holdings.html @@ -7,32 +7,23 @@
-
-
- - - - - - - - -
-
+
- @if (viewModeFormControl.value === 'CHART') { + @if (holdingsViewMode === 'CHART') { } -
+