From 85a0b38c020a734bf5290e1ad51991d6e151f28f Mon Sep 17 00:00:00 2001 From: Shivansh-22866 Date: Sat, 4 Oct 2025 16:02:56 +0530 Subject: [PATCH] Add Custom SWR and style for Select Component --- .../portfolio/fire/fire-page.component.ts | 42 +++++++++++++++---- .../app/pages/portfolio/fire/fire-page.html | 22 ++++++---- .../app/pages/portfolio/fire/fire-page.scss | 18 ++++++++ 3 files changed, 65 insertions(+), 17 deletions(-) diff --git a/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts b/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts index ab0fbc787..4db906178 100644 --- a/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts +++ b/apps/client/src/app/pages/portfolio/fire/fire-page.component.ts @@ -6,8 +6,8 @@ import { hasPermission, permissions } from '@ghostfolio/common/permissions'; import { GfFireCalculatorComponent } from '@ghostfolio/ui/fire-calculator'; import { GfPremiumIndicatorComponent } from '@ghostfolio/ui/premium-indicator'; import { GfValueComponent } from '@ghostfolio/ui/value'; - -import { NgStyle } from '@angular/common'; +import { FormsModule } from '@angular/forms'; +import { CommonModule, NgStyle } from '@angular/common'; import { ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; import { Big } from 'big.js'; import { DeviceDetectorService } from 'ngx-device-detector'; @@ -17,6 +17,8 @@ import { takeUntil } from 'rxjs/operators'; @Component({ imports: [ + CommonModule, + FormsModule, GfFireCalculatorComponent, GfPremiumIndicatorComponent, GfValueComponent, @@ -33,6 +35,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit { public hasImpersonationId: boolean; public hasPermissionToUpdateUserSettings: boolean; public isLoading = false; + public safeWithdrawalRateOptions = [0.025, 0.03, 0.035, 0.04, 0.045]; public user: User; public withdrawalRatePerMonth: Big; public withdrawalRatePerYear: Big; @@ -63,11 +66,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit { this.fireWealth = new Big(10000); } - this.withdrawalRatePerYear = this.fireWealth.mul( - this.user.settings.safeWithdrawalRate - ); - - this.withdrawalRatePerMonth = this.withdrawalRatePerYear.div(12); + this._calculateWithdrawalRates(); this.isLoading = false; @@ -95,6 +94,7 @@ export class GfFirePageComponent implements OnDestroy, OnInit { permissions.updateUserSettings ); + this._calculateWithdrawalRates(); this.changeDetectorRef.markForCheck(); } }); @@ -134,6 +134,22 @@ export class GfFirePageComponent implements OnDestroy, OnInit { }); }); } + + public onSafeWithdrawalRateChange(safeWithdrawalRate: number) { + this.dataService + .putUserSetting({ safeWithdrawalRate }) // No need for Number() conversion + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe(() => { + this.userService + .get(true) + .pipe(takeUntil(this.unsubscribeSubject)) + .subscribe((user) => { + this.user = user; + this._calculateWithdrawalRates(); + this.changeDetectorRef.markForCheck(); + }); + }); + } public onSavingsRateChange(savingsRate: number) { this.dataService .putUserSetting({ savingsRate }) @@ -173,4 +189,14 @@ export class GfFirePageComponent implements OnDestroy, OnInit { this.unsubscribeSubject.next(); this.unsubscribeSubject.complete(); } -} + + private _calculateWithdrawalRates() { + if (this.fireWealth && this.user?.settings?.safeWithdrawalRate) { + this.withdrawalRatePerYear = this.fireWealth.mul( + this.user.settings.safeWithdrawalRate + ); + + this.withdrawalRatePerMonth = this.withdrawalRatePerYear.div(12); + } + } +} \ No newline at end of file diff --git a/apps/client/src/app/pages/portfolio/fire/fire-page.html b/apps/client/src/app/pages/portfolio/fire/fire-page.html index df81991c3..757c881ca 100644 --- a/apps/client/src/app/pages/portfolio/fire/fire-page.html +++ b/apps/client/src/app/pages/portfolio/fire/fire-page.html @@ -106,15 +106,19 @@   and a safe withdrawal rate (SWR) of   - . + . } - + \ No newline at end of file diff --git a/apps/client/src/app/pages/portfolio/fire/fire-page.scss b/apps/client/src/app/pages/portfolio/fire/fire-page.scss index 5d4e87f30..d503f55c2 100644 --- a/apps/client/src/app/pages/portfolio/fire/fire-page.scss +++ b/apps/client/src/app/pages/portfolio/fire/fire-page.scss @@ -1,3 +1,21 @@ :host { display: block; } + +.swr-select { + background-color: transparent; + border: 0; + + color: white; + + &:focus { + box-shadow: none; + outline: 0; + } + + option { + background: #1c1c1e; + color: white; + border: 0; + } +} \ No newline at end of file