Skip to content

Commit

Permalink
fix(editor): Unsubscribe from observable subscription (#620)
Browse files Browse the repository at this point in the history
  • Loading branch information
Angi-Kinas authored Sep 18, 2023
1 parent f4117be commit bfd28df
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
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'
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',
Expand All @@ -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()
}
}

0 comments on commit bfd28df

Please sign in to comment.