Browse Source

Task/eliminate OnDestroy lifecycle hook from admin users component (#6565)

* Eliminate OnDestroy lifecycle hook
pull/6089/merge
Erwin 1 week ago
committed by GitHub
parent
commit
a458608bd6
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 26
      apps/client/src/app/components/admin-users/admin-users.component.ts

26
apps/client/src/app/components/admin-users/admin-users.component.ts

@ -25,10 +25,11 @@ import { CommonModule } from '@angular/common';
import { import {
ChangeDetectorRef, ChangeDetectorRef,
Component, Component,
OnDestroy, DestroyRef,
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';
@ -55,8 +56,7 @@ import {
} from 'ionicons/icons'; } from 'ionicons/icons';
import { DeviceDetectorService } from 'ngx-device-detector'; import { DeviceDetectorService } from 'ngx-device-detector';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { Subject } from 'rxjs'; import { switchMap, tap } from 'rxjs/operators';
import { switchMap, takeUntil, tap } from 'rxjs/operators';
@Component({ @Component({
imports: [ imports: [
@ -75,7 +75,7 @@ import { switchMap, takeUntil, tap } from 'rxjs/operators';
styleUrls: ['./admin-users.scss'], styleUrls: ['./admin-users.scss'],
templateUrl: './admin-users.html' templateUrl: './admin-users.html'
}) })
export class GfAdminUsersComponent implements OnDestroy, OnInit { export class GfAdminUsersComponent implements OnInit {
@ViewChild(MatPaginator) paginator: MatPaginator; @ViewChild(MatPaginator) paginator: MatPaginator;
public dataSource = new MatTableDataSource<AdminUsersResponse['users'][0]>(); public dataSource = new MatTableDataSource<AdminUsersResponse['users'][0]>();
@ -93,12 +93,11 @@ export class GfAdminUsersComponent implements OnDestroy, OnInit {
public totalItems = 0; public totalItems = 0;
public user: User; public user: User;
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 impersonationStorageService: ImpersonationStorageService, private impersonationStorageService: ImpersonationStorageService,
@ -139,7 +138,7 @@ export class GfAdminUsersComponent implements OnDestroy, OnInit {
this.userService.stateChanged this.userService.stateChanged
.pipe( .pipe(
takeUntil(this.unsubscribeSubject), takeUntilDestroyed(this.destroyRef),
tap((state) => { tap((state) => {
if (state?.user) { if (state?.user) {
this.user = state.user; this.user = state.user;
@ -204,7 +203,7 @@ export class GfAdminUsersComponent implements OnDestroy, OnInit {
confirmFn: () => { confirmFn: () => {
this.dataService this.dataService
.deleteUser(aId) .deleteUser(aId)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(() => { .subscribe(() => {
this.router.navigate(['..'], { relativeTo: this.route }); this.router.navigate(['..'], { relativeTo: this.route });
}); });
@ -222,7 +221,7 @@ export class GfAdminUsersComponent implements OnDestroy, OnInit {
confirmFn: () => { confirmFn: () => {
this.dataService this.dataService
.updateUserAccessToken(aUserId) .updateUserAccessToken(aUserId)
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ accessToken }) => { .subscribe(({ accessToken }) => {
this.notificationService.alert({ this.notificationService.alert({
discardFn: () => { discardFn: () => {
@ -258,11 +257,6 @@ export class GfAdminUsersComponent implements OnDestroy, OnInit {
); );
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
private fetchUsers({ pageIndex }: { pageIndex: number } = { pageIndex: 0 }) { private fetchUsers({ pageIndex }: { pageIndex: number } = { pageIndex: 0 }) {
this.isLoading = true; this.isLoading = true;
@ -275,7 +269,7 @@ export class GfAdminUsersComponent implements OnDestroy, OnInit {
skip: pageIndex * this.pageSize, skip: pageIndex * this.pageSize,
take: this.pageSize take: this.pageSize
}) })
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe(({ count, users }) => { .subscribe(({ count, users }) => {
this.dataSource = new MatTableDataSource(users); this.dataSource = new MatTableDataSource(users);
this.totalItems = count; this.totalItems = count;
@ -305,7 +299,7 @@ export class GfAdminUsersComponent implements OnDestroy, OnInit {
dialogRef dialogRef
.afterClosed() .afterClosed()
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((data) => { .subscribe((data) => {
if (data?.action === 'delete' && data?.userId) { if (data?.action === 'delete' && data?.userId) {
this.onDeleteUser(data.userId); this.onDeleteUser(data.userId);

Loading…
Cancel
Save