Browse Source

Task/eliminate OnDestroy lifecycle hook from activities table page (#6672)

Eliminate OnDestroy lifecycle hook
pull/6679/head
Erwin 6 days ago
committed by GitHub
parent
commit
1b26b6ced0
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 20
      libs/ui/src/lib/activities-table/activities-table.component.ts

20
libs/ui/src/lib/activities-table/activities-table.component.ts

@ -20,9 +20,9 @@ import {
CUSTOM_ELEMENTS_SCHEMA, CUSTOM_ELEMENTS_SCHEMA,
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
DestroyRef,
EventEmitter, EventEmitter,
Input, Input,
OnDestroy,
OnInit, OnInit,
Output, Output,
ViewChild, ViewChild,
@ -30,6 +30,7 @@ import {
inject, inject,
input input
} from '@angular/core'; } from '@angular/core';
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { FormControl, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button'; import { MatButtonModule } from '@angular/material/button';
import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatCheckboxModule } from '@angular/material/checkbox';
@ -68,7 +69,6 @@ import {
trashOutline trashOutline
} from 'ionicons/icons'; } from 'ionicons/icons';
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader';
import { Subject, takeUntil } from 'rxjs';
import { GfActivityTypeComponent } from '../activity-type/activity-type.component'; import { GfActivityTypeComponent } from '../activity-type/activity-type.component';
import { GfEntityLogoComponent } from '../entity-logo/entity-logo.component'; import { GfEntityLogoComponent } from '../entity-logo/entity-logo.component';
@ -102,9 +102,7 @@ import { GfValueComponent } from '../value/value.component';
styleUrls: ['./activities-table.component.scss'], styleUrls: ['./activities-table.component.scss'],
templateUrl: './activities-table.component.html' templateUrl: './activities-table.component.html'
}) })
export class GfActivitiesTableComponent export class GfActivitiesTableComponent implements AfterViewInit, OnInit {
implements AfterViewInit, OnDestroy, OnInit
{
@Input() baseCurrency: string; @Input() baseCurrency: string;
@Input() deviceType: string; @Input() deviceType: string;
@Input() hasActivities: boolean; @Input() hasActivities: boolean;
@ -198,9 +196,8 @@ export class GfActivitiesTableComponent
}); });
private readonly notificationService = inject(NotificationService); private readonly notificationService = inject(NotificationService);
private readonly unsubscribeSubject = new Subject<void>();
public constructor() { public constructor(private destroyRef: DestroyRef) {
for (const type of Object.keys(ActivityType) as ActivityType[]) { for (const type of Object.keys(ActivityType) as ActivityType[]) {
this.activityTypesTranslationMap.set( this.activityTypesTranslationMap.set(
ActivityType[type], ActivityType[type],
@ -228,14 +225,14 @@ export class GfActivitiesTableComponent
if (this.showCheckbox()) { if (this.showCheckbox()) {
this.toggleAllRows(); this.toggleAllRows();
this.selectedRows.changed this.selectedRows.changed
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((selectedRows) => { .subscribe((selectedRows) => {
this.selectedActivities.emit(selectedRows.source.selected); this.selectedActivities.emit(selectedRows.source.selected);
}); });
} }
this.typesFilter.valueChanges this.typesFilter.valueChanges
.pipe(takeUntil(this.unsubscribeSubject)) .pipe(takeUntilDestroyed(this.destroyRef))
.subscribe((types) => { .subscribe((types) => {
this.typesFilterChanged.emit(types ?? []); this.typesFilterChanged.emit(types ?? []);
}); });
@ -367,9 +364,4 @@ export class GfActivitiesTableComponent
this.selectedActivities.emit(this.selectedRows.selected); this.selectedActivities.emit(this.selectedRows.selected);
} }
public ngOnDestroy() {
this.unsubscribeSubject.next();
this.unsubscribeSubject.complete();
}
} }

Loading…
Cancel
Save