From bfd28df408e9828eb2608e7f5f278313d3e0ccac Mon Sep 17 00:00:00 2001 From: Angi-Kinas <133115263+Angi-Kinas@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:33:38 +0200 Subject: [PATCH] fix(editor): Unsubscribe from observable subscription (#620) --- .../my-org-records.component.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts b/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts index 9c9ac5319f..f703c1ff07 100644 --- a/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts +++ b/apps/metadata-editor/src/app/records/my-org-records/my-org-records.component.ts @@ -1,4 +1,4 @@ -import { Component } from '@angular/core' +import { Component, OnDestroy } from '@angular/core' import { CommonModule } from '@angular/common' import { TranslateModule } from '@ngx-translate/core' import { RecordsListComponent } from '../records-list.component' @@ -6,6 +6,7 @@ import { SearchFacade } from '@geonetwork-ui/feature/search' import { OrganizationsServiceInterface } from '@geonetwork-ui/common/domain/organizations.service.interface' import { Organization } from '@geonetwork-ui/common/domain/record' import { AuthService } from '@geonetwork-ui/feature/auth' +import { Subscription } from 'rxjs' @Component({ selector: 'md-editor-my-org-records', @@ -14,21 +15,30 @@ import { AuthService } from '@geonetwork-ui/feature/auth' standalone: true, imports: [CommonModule, TranslateModule, RecordsListComponent], }) -export class MyOrgRecordsComponent { +export class MyOrgRecordsComponent implements OnDestroy { + subscriptionAuthService: Subscription + subscriptionOrgService: Subscription + constructor( public searchFacade: SearchFacade, private authService: AuthService, private orgService: OrganizationsServiceInterface ) { this.searchFacade.resetSearch() - this.authService.user$.subscribe((user) => { - this.searchByOrganisation({ name: user.organisation }) + + this.subscriptionAuthService = this.authService.user$.subscribe((user) => { + this.searchByOrganisation({ name: user?.organisation }) }) } searchByOrganisation(organisation: Organization) { - this.orgService + this.subscriptionOrgService = this.orgService .getFiltersForOrgs([organisation]) .subscribe((filters) => this.searchFacade.setFilters(filters)) } + + ngOnDestroy(): void { + this.subscriptionAuthService.unsubscribe() + this.subscriptionOrgService.unsubscribe() + } }