Browse Source

feat(client): convert user to signal

pull/6927/head
KenTandrian 2 days ago
parent
commit
b4670a8315
  1. 22
      apps/client/src/app/components/home-overview/home-overview.component.ts
  2. 16
      apps/client/src/app/components/home-overview/home-overview.html

22
apps/client/src/app/components/home-overview/home-overview.component.ts

@ -62,7 +62,7 @@ export class GfHomeOverviewComponent implements OnInit {
internalRoutes.portfolio.subRoutes.activities.routerLink; internalRoutes.portfolio.subRoutes.activities.routerLink;
protected showDetails = false; protected showDetails = false;
protected unit: string; protected unit: string;
protected user: User; protected readonly user = signal<User | null>(null);
private readonly changeDetectorRef = inject(ChangeDetectorRef); private readonly changeDetectorRef = inject(ChangeDetectorRef);
private readonly dataService = inject(DataService); private readonly dataService = inject(DataService);
@ -79,10 +79,10 @@ export class GfHomeOverviewComponent implements OnInit {
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((state) => { .subscribe((state) => {
if (state?.user) { if (state?.user) {
this.user = state.user; this.user.set(state.user);
this.hasPermissionToCreateActivity = hasPermission( this.hasPermissionToCreateActivity = hasPermission(
this.user.permissions, this.user()?.permissions,
permissions.createActivity permissions.createActivity
); );
@ -92,13 +92,15 @@ export class GfHomeOverviewComponent implements OnInit {
} }
public ngOnInit() { public ngOnInit() {
this.showDetails = const user = this.user();
!this.user.settings.isRestrictedView && if (user) {
this.user.settings.viewMode !== 'ZEN'; this.showDetails =
!user.settings.isRestrictedView && user.settings.viewMode !== 'ZEN';
this.unit = this.showDetails this.unit = this.showDetails
? (this.user.settings.baseCurrency ?? DEFAULT_CURRENCY) ? (user.settings.baseCurrency ?? DEFAULT_CURRENCY)
: '%'; : '%';
}
this.impersonationStorageService this.impersonationStorageService
.onChangeHasImpersonation() .onChangeHasImpersonation()
@ -120,7 +122,7 @@ export class GfHomeOverviewComponent implements OnInit {
this.dataService this.dataService
.fetchPortfolioPerformance({ .fetchPortfolioPerformance({
range: this.user?.settings?.dateRange ?? DEFAULT_DATE_RANGE range: this.user()?.settings?.dateRange ?? DEFAULT_DATE_RANGE
}) })
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ chart, errors, performance }) => { .subscribe(({ chart, errors, performance }) => {

16
apps/client/src/app/components/home-overview/home-overview.html

@ -4,14 +4,14 @@
@if ( @if (
!hasImpersonationId() && !hasImpersonationId() &&
hasPermissionToCreateActivity && hasPermissionToCreateActivity &&
user?.activitiesCount === 0 user()?.activitiesCount === 0
) { ) {
<div class="justify-content-center row w-100"> <div class="justify-content-center row w-100">
<div class="col introduction"> <div class="col introduction">
<h4 i18n>Welcome to Ghostfolio</h4> <h4 i18n>Welcome to Ghostfolio</h4>
<p i18n>Ready to take control of your personal finances?</p> <p i18n>Ready to take control of your personal finances?</p>
<ol class="font-weight-bold"> <ol class="font-weight-bold">
<li class="mb-2" [class.text-muted]="user?.accounts?.length > 1"> <li class="mb-2" [class.text-muted]="user()?.accounts?.length > 1">
<a class="d-block" [routerLink]="routerLinkAccounts" <a class="d-block" [routerLink]="routerLinkAccounts"
><span i18n>Setup your accounts</span><br /> ><span i18n>Setup your accounts</span><br />
<span class="font-weight-normal" i18n <span class="font-weight-normal" i18n
@ -40,7 +40,7 @@
</li> </li>
</ol> </ol>
<div class="d-flex justify-content-center"> <div class="d-flex justify-content-center">
@if (user?.accounts?.length === 1) { @if (user()?.accounts?.length === 1) {
<a <a
color="primary" color="primary"
mat-flat-button mat-flat-button
@ -48,7 +48,7 @@
> >
<ng-container i18n>Setup accounts</ng-container> <ng-container i18n>Setup accounts</ng-container>
</a> </a>
} @else if (user?.accounts?.length > 1) { } @else if (user()?.accounts?.length > 1) {
<a <a
color="primary" color="primary"
mat-flat-button mat-flat-button
@ -68,12 +68,12 @@
class="position-absolute" class="position-absolute"
unit="%" unit="%"
[class.pr-3]="deviceType() === 'mobile'" [class.pr-3]="deviceType() === 'mobile'"
[colorScheme]="user?.settings?.colorScheme" [colorScheme]="user()?.settings?.colorScheme"
[hidden]="historicalDataItems?.length === 0" [hidden]="historicalDataItems?.length === 0"
[historicalDataItems]="historicalDataItems" [historicalDataItems]="historicalDataItems"
[isAnimated]="user?.settings?.dateRange === '1d' ? false : true" [isAnimated]="user()?.settings?.dateRange === '1d' ? false : true"
[label]="performanceLabel" [label]="performanceLabel"
[locale]="user?.settings?.locale" [locale]="user()?.settings?.locale"
[showGradient]="true" [showGradient]="true"
[showLoader]="false" [showLoader]="false"
[showXAxis]="false" [showXAxis]="false"
@ -89,7 +89,7 @@
[deviceType]="deviceType()" [deviceType]="deviceType()"
[errors]="errors()" [errors]="errors()"
[isLoading]="isLoadingPerformance" [isLoading]="isLoadingPerformance"
[locale]="user?.settings?.locale" [locale]="user()?.settings?.locale"
[performance]="performance" [performance]="performance"
[precision]="precision" [precision]="precision"
[showDetails]="showDetails" [showDetails]="showDetails"

Loading…
Cancel
Save