Browse Source

Task/improve type safety for app component (#6626)

* Improve type safety
pull/6614/head^2
Kenrick Tandrian 4 days ago
committed by GitHub
parent
commit
4d8eec4452
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 85
      apps/client/src/app/app.component.ts
  2. 8
      apps/client/src/app/interfaces/interfaces.ts

85
apps/client/src/app/app.component.ts

@ -13,7 +13,7 @@ import {
DestroyRef, DestroyRef,
DOCUMENT, DOCUMENT,
HostBinding, HostBinding,
Inject, inject,
OnInit OnInit
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
@ -36,7 +36,7 @@ import { filter } from 'rxjs/operators';
import { GfFooterComponent } from './components/footer/footer.component'; import { GfFooterComponent } from './components/footer/footer.component';
import { GfHeaderComponent } from './components/header/header.component'; import { GfHeaderComponent } from './components/header/header.component';
import { GfHoldingDetailDialogComponent } from './components/holding-detail-dialog/holding-detail-dialog.component'; import { GfHoldingDetailDialogComponent } from './components/holding-detail-dialog/holding-detail-dialog.component';
import { HoldingDetailDialogParams } from './components/holding-detail-dialog/interfaces/interfaces'; import { GfAppQueryParams } from './interfaces/interfaces';
import { ImpersonationStorageService } from './services/impersonation-storage.service'; import { ImpersonationStorageService } from './services/impersonation-storage.service';
import { UserService } from './services/user/user.service'; import { UserService } from './services/user/user.service';
@ -48,10 +48,6 @@ import { UserService } from './services/user/user.service';
templateUrl: './app.component.html' templateUrl: './app.component.html'
}) })
export class GfAppComponent implements OnInit { export class GfAppComponent implements OnInit {
@HostBinding('class.has-info-message') get getHasMessage() {
return this.hasInfoMessage;
}
public canCreateAccount: boolean; public canCreateAccount: boolean;
public currentRoute: string; public currentRoute: string;
public currentSubRoute: string; public currentSubRoute: string;
@ -66,43 +62,47 @@ export class GfAppComponent implements OnInit {
public pageTitle: string; public pageTitle: string;
public routerLinkRegister = publicRoutes.register.routerLink; public routerLinkRegister = publicRoutes.register.routerLink;
public showFooter = false; public showFooter = false;
public user: User; public user: User | undefined;
public constructor( private readonly changeDetectorRef = inject(ChangeDetectorRef);
private changeDetectorRef: ChangeDetectorRef, private readonly dataService = inject(DataService);
private dataService: DataService, private readonly destroyRef = inject(DestroyRef);
private destroyRef: DestroyRef, private readonly deviceService = inject(DeviceDetectorService);
private deviceService: DeviceDetectorService, private readonly dialog = inject(MatDialog);
private dialog: MatDialog, private readonly document = inject(DOCUMENT);
@Inject(DOCUMENT) private document: Document, private readonly impersonationStorageService = inject(
private impersonationStorageService: ImpersonationStorageService, ImpersonationStorageService
private notificationService: NotificationService, );
private route: ActivatedRoute, private readonly notificationService = inject(NotificationService);
private router: Router, private readonly route = inject(ActivatedRoute);
private title: Title, private readonly router = inject(Router);
private userService: UserService private readonly title = inject(Title);
) { private readonly userService = inject(UserService);
public constructor() {
this.initializeTheme(); this.initializeTheme();
this.user = undefined; this.user = undefined;
this.route.queryParams this.route.queryParams
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params) => { .subscribe(
if ( ({ dataSource, holdingDetailDialog, symbol }: GfAppQueryParams) => {
params['dataSource'] && if (dataSource && holdingDetailDialog && symbol) {
params['holdingDetailDialog'] &&
params['symbol']
) {
this.openHoldingDetailDialog({ this.openHoldingDetailDialog({
dataSource: params['dataSource'], dataSource,
symbol: params['symbol'] symbol
}); });
} }
}); }
);
addIcons({ openOutline }); addIcons({ openOutline });
} }
@HostBinding('class.has-info-message') get getHasMessage() {
return this.hasInfoMessage;
}
public ngOnInit() { public ngOnInit() {
this.deviceType = this.deviceService.getDeviceInfo().deviceType; this.deviceType = this.deviceService.getDeviceInfo().deviceType;
this.info = this.dataService.fetchInfo(); this.info = this.dataService.fetchInfo();
@ -128,7 +128,7 @@ export class GfAppComponent implements OnInit {
!this.currentSubRoute) || !this.currentSubRoute) ||
(this.currentRoute === internalRoutes.home.path && (this.currentRoute === internalRoutes.home.path &&
this.currentSubRoute === this.currentSubRoute ===
internalRoutes.home.subRoutes.holdings.path) || internalRoutes.home.subRoutes?.holdings.path) ||
(this.currentRoute === internalRoutes.portfolio.path && (this.currentRoute === internalRoutes.portfolio.path &&
!this.currentSubRoute)) && !this.currentSubRoute)) &&
this.user?.settings?.viewMode !== 'ZEN' this.user?.settings?.viewMode !== 'ZEN'
@ -223,11 +223,17 @@ export class GfAppComponent implements OnInit {
} }
public onClickSystemMessage() { public onClickSystemMessage() {
if (this.user.systemMessage.routerLink) { const systemMessage = this.user?.systemMessage;
this.router.navigate(this.user.systemMessage.routerLink);
if (!systemMessage) {
return;
}
if (systemMessage.routerLink) {
void this.router.navigate(systemMessage.routerLink);
} else { } else {
this.notificationService.alert({ this.notificationService.alert({
title: this.user.systemMessage.message title: systemMessage.message
}); });
} }
} }
@ -269,10 +275,7 @@ export class GfAppComponent implements OnInit {
.subscribe((user) => { .subscribe((user) => {
this.user = user; this.user = user;
const dialogRef = this.dialog.open< const dialogRef = this.dialog.open(GfHoldingDetailDialogComponent, {
GfHoldingDetailDialogComponent,
HoldingDetailDialogParams
>(GfHoldingDetailDialogComponent, {
autoFocus: false, autoFocus: false,
data: { data: {
dataSource, dataSource,
@ -313,7 +316,7 @@ export class GfAppComponent implements OnInit {
.afterClosed() .afterClosed()
.pipe(takeUntilDestroyed(this.destroyRef)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => { .subscribe(() => {
this.router.navigate([], { void this.router.navigate([], {
queryParams: { queryParams: {
dataSource: null, dataSource: null,
holdingDetailDialog: null, holdingDetailDialog: null,
@ -339,6 +342,6 @@ export class GfAppComponent implements OnInit {
this.document this.document
.querySelector('meta[name="theme-color"]') .querySelector('meta[name="theme-color"]')
.setAttribute('content', themeColor); ?.setAttribute('content', themeColor);
} }
} }

8
apps/client/src/app/interfaces/interfaces.ts

@ -0,0 +1,8 @@
import type { Params } from '@angular/router';
import type { DataSource } from '@prisma/client';
export interface GfAppQueryParams extends Params {
dataSource?: DataSource;
holdingDetailDialog?: string;
symbol?: string;
}
Loading…
Cancel
Save