Browse Source

Task/eliminate OnDestroy lifecycle hook from admin tag component (#6561)

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

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

@ -10,11 +10,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';
@ -31,7 +32,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 { GfCreateOrUpdateTagDialogComponent } from './create-or-update-tag-dialog/create-or-update-tag-dialog.component'; import { GfCreateOrUpdateTagDialogComponent } from './create-or-update-tag-dialog/create-or-update-tag-dialog.component';
import { CreateOrUpdateTagDialogParams } from './create-or-update-tag-dialog/interfaces/interfaces'; import { CreateOrUpdateTagDialogParams } from './create-or-update-tag-dialog/interfaces/interfaces';
@ -51,7 +51,7 @@ import { CreateOrUpdateTagDialogParams } from './create-or-update-tag-dialog/int
styleUrls: ['./admin-tag.component.scss'], styleUrls: ['./admin-tag.component.scss'],
templateUrl: './admin-tag.component.html' templateUrl: './admin-tag.component.html'
}) })
export class GfAdminTagComponent implements OnDestroy, OnInit { export class GfAdminTagComponent implements OnInit {
@Input() locale = getLocale(); @Input() locale = getLocale();
@ViewChild(MatSort) sort: MatSort; @ViewChild(MatSort) sort: MatSort;
@ -61,11 +61,10 @@ export class GfAdminTagComponent implements OnDestroy, OnInit {
public displayedColumns = ['name', 'userId', 'activities', 'actions']; public displayedColumns = ['name', 'userId', 'activities', 'actions'];
public tags: Tag[]; public tags: Tag[];
private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
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,
@ -74,7 +73,7 @@ export class GfAdminTagComponent 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['createTagDialog']) { if (params['createTagDialog']) {
this.openCreateTagDialog(); this.openCreateTagDialog();
@ -116,20 +115,15 @@ export class GfAdminTagComponent implements OnDestroy, OnInit {
}); });
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private deleteTag(aId: string) { private deleteTag(aId: string) {
this.dataService this.dataService
.deleteTag(aId) .deleteTag(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.fetchTags(); this.fetchTags();
@ -140,7 +134,7 @@ export class GfAdminTagComponent implements OnDestroy, OnInit {
private fetchTags() { private fetchTags() {
this.dataService this.dataService
.fetchTags() .fetchTags()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((tags) => { .subscribe((tags) => {
this.tags = tags; this.tags = tags;
@ -171,17 +165,17 @@ export class GfAdminTagComponent implements OnDestroy, OnInit {
dialogRef dialogRef
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((tag: CreateTagDto | null) => { .subscribe((tag: CreateTagDto | null) => {
if (tag) { if (tag) {
this.dataService this.dataService
.postTag(tag) .postTag(tag)
.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.fetchTags(); this.fetchTags();
@ -210,17 +204,17 @@ export class GfAdminTagComponent implements OnDestroy, OnInit {
dialogRef dialogRef
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((tag: UpdateTagDto | null) => { .subscribe((tag: UpdateTagDto | null) => {
if (tag) { if (tag) {
this.dataService this.dataService
.putTag(tag) .putTag(tag)
.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.fetchTags(); this.fetchTags();

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

@ -1,12 +1,7 @@
import { CreateTagDto, UpdateTagDto } from '@ghostfolio/common/dtos'; import { CreateTagDto, UpdateTagDto } from '@ghostfolio/common/dtos';
import { validateObjectForForm } from '@ghostfolio/common/utils'; import { validateObjectForForm } from '@ghostfolio/common/utils';
import { import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
ChangeDetectionStrategy,
Component,
Inject,
OnDestroy
} from '@angular/core';
import { import {
FormBuilder, FormBuilder,
FormGroup, FormGroup,
@ -21,7 +16,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 { CreateOrUpdateTagDialogParams } from './interfaces/interfaces'; import { CreateOrUpdateTagDialogParams } from './interfaces/interfaces';
@ -40,11 +34,9 @@ import { CreateOrUpdateTagDialogParams } from './interfaces/interfaces';
styleUrls: ['./create-or-update-tag-dialog.scss'], styleUrls: ['./create-or-update-tag-dialog.scss'],
templateUrl: 'create-or-update-tag-dialog.html' templateUrl: 'create-or-update-tag-dialog.html'
}) })
export class GfCreateOrUpdateTagDialogComponent implements OnDestroy { export class GfCreateOrUpdateTagDialogComponent {
public tagForm: FormGroup; public tagForm: FormGroup;
private unsubscribeSubject = new Subject<void>();
public constructor( public constructor(
@Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateTagDialogParams, @Inject(MAT_DIALOG_DATA) public data: CreateOrUpdateTagDialogParams,
public dialogRef: MatDialogRef<GfCreateOrUpdateTagDialogComponent>, public dialogRef: MatDialogRef<GfCreateOrUpdateTagDialogComponent>,
@ -85,9 +77,4 @@ export class GfCreateOrUpdateTagDialogComponent implements OnDestroy {
console.error(error); console.error(error);
} }
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
} }

Loading…
Cancel
Save