From e1a36972b147c7f69c1e037cf5a187af86ff9a95 Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Wed, 16 Feb 2022 01:06:22 -0800 Subject: [PATCH] cleanup subscriptions --- .../app-frame/app-frame.component.ts | 36 +++++++-------- .../document-detail.component.html | 2 +- .../document-detail.component.ts | 45 +++++++------------ src-ui/src/app/guards/dirty-form.guard.ts | 2 +- .../app/services/open-documents.service.ts | 29 +++++++++--- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/src-ui/src/app/components/app-frame/app-frame.component.ts b/src-ui/src/app/components/app-frame/app-frame.component.ts index 4657910a0..74f3cd5b5 100644 --- a/src-ui/src/app/components/app-frame/app-frame.component.ts +++ b/src-ui/src/app/components/app-frame/app-frame.component.ts @@ -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') diff --git a/src-ui/src/app/components/document-detail/document-detail.component.html b/src-ui/src/app/components/document-detail/document-detail.component.html index 96b5938f2..4450f3d49 100644 --- a/src-ui/src/app/components/document-detail/document-detail.component.html +++ b/src-ui/src/app/components/document-detail/document-detail.component.html @@ -38,7 +38,7 @@  More like this -