cleanup subscriptions

This commit is contained in:
Michael Shamoon
2022-02-16 01:06:22 -08:00
parent a4e0056c79
commit 87ee532798
5 changed files with 57 additions and 57 deletions

View File

@@ -1,8 +1,8 @@
import { Component, OnDestroy } from '@angular/core';
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { ActivatedRoute, Router, Params } from '@angular/router';
import { from, Observable, Subscription, BehaviorSubject } from 'rxjs';
import { debounceTime, distinctUntilChanged, map, switchMap } from 'rxjs/operators';
import { debounceTime, distinctUntilChanged, map, switchMap, first } from 'rxjs/operators';
import { PaperlessDocument } from 'src/app/data/paperless-document';
import { OpenDocumentsService } from 'src/app/services/open-documents.service';
import { SavedViewService } from 'src/app/services/rest/saved-view.service';
@@ -18,7 +18,7 @@ import { FILTER_FULLTEXT_QUERY } from 'src/app/data/filter-rule-type';
templateUrl: './app-frame.component.html',
styleUrls: ['./app-frame.component.scss']
})
export class AppFrameComponent implements OnDestroy {
export class AppFrameComponent {
constructor (
public router: Router,
@@ -40,8 +40,6 @@ export class AppFrameComponent implements OnDestroy {
searchField = new FormControl('')
closeAllSub: Subscription
get openDocuments(): PaperlessDocument[] {
return this.openDocumentsService.getOpenDocuments()
}
@@ -81,21 +79,23 @@ export class AppFrameComponent implements OnDestroy {
}
closeDocument(d: PaperlessDocument) {
this.closeMenu()
this.openDocumentsService.closeDocument(d)
let route = this.activatedRoute.snapshot
while (route.firstChild) {
route = route.firstChild
}
if (route.component == DocumentDetailComponent && route.params['id'] == d.id) {
this.router.navigate([""])
}
this.openDocumentsService.closeDocument(d).pipe(first()).subscribe(confirmed => {
if (confirmed) {
this.closeMenu()
let route = this.activatedRoute.snapshot
while (route.firstChild) {
route = route.firstChild
}
if (route.component == DocumentDetailComponent && route.params['id'] == d.id) {
this.router.navigate([""])
}
}
})
}
closeAll() {
// user may need to confirm losing unsaved changes
this.closeAllSub = this.openDocumentsService.closeAll().subscribe(confirmed => {
this.openDocumentsService.closeAll().pipe(first()).subscribe(confirmed => {
if (confirmed) {
this.closeMenu()
@@ -111,10 +111,6 @@ export class AppFrameComponent implements OnDestroy {
})
}
ngOnDestroy() {
this.closeAllSub && this.closeAllSub.unsubscribe();
}
get displayName() {
// TODO: taken from dashboard component, is this the best way to pass around username?
let tagFullName = this.meta.getTag('name=full_name')