Browse Source

Task/eliminate OnDestroy lifecycle hook from admin platform component (#6553)

* Eliminate OnDestroy lifecycle hook
pull/6560/head
Erwin 1 week ago
committed by GitHub
parent
commit
f469bb9d36
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 34
      apps/client/src/app/components/admin-platform/admin-platform.component.ts
  2. 17
      apps/client/src/app/components/admin-platform/create-or-update-platform-dialog/create-or-update-platform-dialog.component.ts

34
apps/client/src/app/components/admin-platform/admin-platform.component.ts

@ -11,11 +11,12 @@ import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
DestroyRef,
Input, Input,
OnDestroy,
OnInit, OnInit,
ViewChild ViewChild
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatDialog } from '@angular/material/dialog'; import { MatDialog } from '@angular/material/dialog';
import { MatMenuModule } from '@angular/material/menu'; import { MatMenuModule } from '@angular/material/menu';
@ -32,7 +33,6 @@ import {
} from 'ionicons/icons'; } from 'ionicons/icons';
import { get } from 'lodash'; import { get } from 'lodash';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { Subject, takeUntil } from 'rxjs';
import { GfCreateOrUpdatePlatformDialogComponent } from './create-or-update-platform-dialog/create-or-update-platform-dialog.component'; import { GfCreateOrUpdatePlatformDialogComponent } from './create-or-update-platform-dialog/create-or-update-platform-dialog.component';
import { CreateOrUpdatePlatformDialogParams } from './create-or-update-platform-dialog/interfaces/interfaces'; import { CreateOrUpdatePlatformDialogParams } from './create-or-update-platform-dialog/interfaces/interfaces';
@ -53,7 +53,7 @@ import { CreateOrUpdatePlatformDialogParams } from './create-or-update-platform-
styleUrls: ['./admin-platform.component.scss'], styleUrls: ['./admin-platform.component.scss'],
templateUrl: './admin-platform.component.html' templateUrl: './admin-platform.component.html'
}) })
export class GfAdminPlatformComponent implements OnDestroy, OnInit { export class GfAdminPlatformComponent implements OnInit {
@Input() locale = getLocale(); @Input() locale = getLocale();
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -63,12 +63,11 @@ export class GfAdminPlatformComponent implements OnDestroy, OnInit {
public displayedColumns = ['name', 'url', 'accounts', 'actions']; public displayedColumns = ['name', 'url', 'accounts', 'actions'];
public platforms: Platform[]; public platforms: Platform[];
private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
private adminService: AdminService, private adminService: AdminService,
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private dataService: DataService, private dataService: DataService,
private destroyRef: DestroyRef,
private deviceService: DeviceDetectorService, private deviceService: DeviceDetectorService,
private dialog: MatDialog, private dialog: MatDialog,
private notificationService: NotificationService, private notificationService: NotificationService,
@ -77,7 +76,7 @@ export class GfAdminPlatformComponent implements OnDestroy, OnInit {
private userService: UserService private userService: UserService
) { ) {
this.route.queryParams this.route.queryParams
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((params) => { .subscribe((params) => {
if (params['createPlatformDialog']) { if (params['createPlatformDialog']) {
this.openCreatePlatformDialog(); this.openCreatePlatformDialog();
@ -119,20 +118,15 @@ export class GfAdminPlatformComponent implements OnDestroy, OnInit {
}); });
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private deletePlatform(aId: string) { private deletePlatform(aId: string) {
this.adminService this.adminService
.deletePlatform(aId) .deletePlatform(aId)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({ .subscribe({
next: () => { next: () => {
this.userService this.userService
.get(true) .get(true)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(); .subscribe();
this.fetchPlatforms(); this.fetchPlatforms();
@ -143,7 +137,7 @@ export class GfAdminPlatformComponent implements OnDestroy, OnInit {
private fetchPlatforms() { private fetchPlatforms() {
this.adminService this.adminService
.fetchPlatforms() .fetchPlatforms()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((platforms) => { .subscribe((platforms) => {
this.platforms = platforms; this.platforms = platforms;
@ -175,17 +169,17 @@ export class GfAdminPlatformComponent implements OnDestroy, OnInit {
dialogRef dialogRef
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((platform: CreatePlatformDto | null) => { .subscribe((platform: CreatePlatformDto | null) => {
if (platform) { if (platform) {
this.adminService this.adminService
.postPlatform(platform) .postPlatform(platform)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({ .subscribe({
next: () => { next: () => {
this.userService this.userService
.get(true) .get(true)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(); .subscribe();
this.fetchPlatforms(); this.fetchPlatforms();
@ -223,17 +217,17 @@ export class GfAdminPlatformComponent implements OnDestroy, OnInit {
dialogRef dialogRef
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((platform: UpdatePlatformDto | null) => { .subscribe((platform: UpdatePlatformDto | null) => {
if (platform) { if (platform) {
this.adminService this.adminService
.putPlatform(platform) .putPlatform(platform)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe({ .subscribe({
next: () => { next: () => {
this.userService this.userService
.get(true) .get(true)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(); .subscribe();
this.fetchPlatforms(); this.fetchPlatforms();

17
apps/client/src/app/components/admin-platform/create-or-update-platform-dialog/create-or-update-platform-dialog.component.ts

@ -2,12 +2,7 @@ import { CreatePlatformDto, UpdatePlatformDto } from '@ghostfolio/common/dtos';
import { validateObjectForForm } from '@ghostfolio/common/utils'; import { validateObjectForForm } from '@ghostfolio/common/utils';
import { GfEntityLogoComponent } from '@ghostfolio/ui/entity-logo'; import { GfEntityLogoComponent } from '@ghostfolio/ui/entity-logo';
import { import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
ChangeDetectionStrategy,
Component,
Inject,
OnDestroy
} from '@angular/core';
import { import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
@ -23,7 +18,6 @@ import {
} from '@angular/material/dialog'; } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { Subject } from 'rxjs';
import { CreateOrUpdatePlatformDialogParams } from './interfaces/interfaces'; import { CreateOrUpdatePlatformDialogParams } from './interfaces/interfaces';
@ -43,11 +37,9 @@ import { CreateOrUpdatePlatformDialogParams } from './interfaces/interfaces';
styleUrls: ['./create-or-update-platform-dialog.scss'], styleUrls: ['./create-or-update-platform-dialog.scss'],
templateUrl: 'create-or-update-platform-dialog.html' templateUrl: 'create-or-update-platform-dialog.html'
}) })
export class GfCreateOrUpdatePlatformDialogComponent implements OnDestroy { export class GfCreateOrUpdatePlatformDialogComponent {
public platformForm: FormGroup; public platformForm: FormGroup;
private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdatePlatformDialogParams, @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdatePlatformDialogParams,
public dialogRef: MatDialogRef<GfCreateOrUpdatePlatformDialogComponent>, public dialogRef: MatDialogRef<GfCreateOrUpdatePlatformDialogComponent>,
@ -90,9 +82,4 @@ export class GfCreateOrUpdatePlatformDialogComponent implements OnDestroy {
console.error(error); console.error(error);
} }
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
} }

Loading…
Cancel
Save