diff options
author | Chocobozzz <me@florianbigard.com> | 2023-02-16 16:13:19 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-02-16 16:13:19 +0100 |
commit | 6e060713b428f479d26993f6fd79a062630d2432 (patch) | |
tree | 2277d0589e5b52f497bbd85650d14cd1de42ed5a /client/src/app/modal | |
parent | 4835b374d04705408e6c458f7ce100d929b2edc1 (diff) | |
download | PeerTube-6e060713b428f479d26993f6fd79a062630d2432.tar.gz PeerTube-6e060713b428f479d26993f6fd79a062630d2432.tar.zst PeerTube-6e060713b428f479d26993f6fd79a062630d2432.zip |
Correctly unsubscribe on menu destroy
Diffstat (limited to 'client/src/app/modal')
-rw-r--r-- | client/src/app/modal/quick-settings-modal.component.ts | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/client/src/app/modal/quick-settings-modal.component.ts b/client/src/app/modal/quick-settings-modal.component.ts index 19f75ad5c..8ba58a23a 100644 --- a/client/src/app/modal/quick-settings-modal.component.ts +++ b/client/src/app/modal/quick-settings-modal.component.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | import { ReplaySubject } from 'rxjs' | 1 | import { ReplaySubject, Subscription } from 'rxjs' |
2 | import { filter } from 'rxjs/operators' | 2 | import { filter } from 'rxjs/operators' |
3 | import { Component, OnInit, ViewChild } from '@angular/core' | 3 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' |
4 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { AuthService, AuthStatus, LocalStorageService, User, UserService } from '@app/core' | 5 | import { AuthService, AuthStatus, LocalStorageService, User, UserService } from '@app/core' |
6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' | 6 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
@@ -10,7 +10,7 @@ import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref' | |||
10 | selector: 'my-quick-settings', | 10 | selector: 'my-quick-settings', |
11 | templateUrl: './quick-settings-modal.component.html' | 11 | templateUrl: './quick-settings-modal.component.html' |
12 | }) | 12 | }) |
13 | export class QuickSettingsModalComponent implements OnInit { | 13 | export class QuickSettingsModalComponent implements OnInit, OnDestroy { |
14 | private static readonly QUERY_MODAL_NAME = 'quick-settings' | 14 | private static readonly QUERY_MODAL_NAME = 'quick-settings' |
15 | 15 | ||
16 | @ViewChild('modal', { static: true }) modal: NgbModal | 16 | @ViewChild('modal', { static: true }) modal: NgbModal |
@@ -20,6 +20,10 @@ export class QuickSettingsModalComponent implements OnInit { | |||
20 | 20 | ||
21 | private openedModal: NgbModalRef | 21 | private openedModal: NgbModalRef |
22 | 22 | ||
23 | private routeSub: Subscription | ||
24 | private loginSub: Subscription | ||
25 | private localStorageSub: Subscription | ||
26 | |||
23 | constructor ( | 27 | constructor ( |
24 | private modalService: NgbModal, | 28 | private modalService: NgbModal, |
25 | private userService: UserService, | 29 | private userService: UserService, |
@@ -32,14 +36,15 @@ export class QuickSettingsModalComponent implements OnInit { | |||
32 | 36 | ||
33 | ngOnInit () { | 37 | ngOnInit () { |
34 | this.user = this.userService.getAnonymousUser() | 38 | this.user = this.userService.getAnonymousUser() |
35 | this.localStorageService.watch() | 39 | |
40 | this.localStorageSub = this.localStorageService.watch() | ||
36 | .subscribe({ | 41 | .subscribe({ |
37 | next: () => this.user = this.userService.getAnonymousUser() | 42 | next: () => this.user = this.userService.getAnonymousUser() |
38 | }) | 43 | }) |
39 | 44 | ||
40 | this.userInformationLoaded.next(true) | 45 | this.userInformationLoaded.next(true) |
41 | 46 | ||
42 | this.authService.loginChangedSource | 47 | this.loginSub = this.authService.loginChangedSource |
43 | .pipe(filter(status => status !== AuthStatus.LoggedIn)) | 48 | .pipe(filter(status => status !== AuthStatus.LoggedIn)) |
44 | .subscribe({ | 49 | .subscribe({ |
45 | next: () => { | 50 | next: () => { |
@@ -48,7 +53,7 @@ export class QuickSettingsModalComponent implements OnInit { | |||
48 | } | 53 | } |
49 | }) | 54 | }) |
50 | 55 | ||
51 | this.route.queryParams.subscribe(params => { | 56 | this.routeSub = this.route.queryParams.subscribe(params => { |
52 | if (params['modal'] === QuickSettingsModalComponent.QUERY_MODAL_NAME) { | 57 | if (params['modal'] === QuickSettingsModalComponent.QUERY_MODAL_NAME) { |
53 | this.openedModal = this.modalService.open(this.modal, { centered: true }) | 58 | this.openedModal = this.modalService.open(this.modal, { centered: true }) |
54 | 59 | ||
@@ -57,6 +62,12 @@ export class QuickSettingsModalComponent implements OnInit { | |||
57 | }) | 62 | }) |
58 | } | 63 | } |
59 | 64 | ||
65 | ngOnDestroy () { | ||
66 | if (this.routeSub) this.routeSub.unsubscribe() | ||
67 | if (this.loginSub) this.loginSub.unsubscribe() | ||
68 | if (this.localStorageSub) this.localStorageSub.unsubscribe() | ||
69 | } | ||
70 | |||
60 | isUserLoggedIn () { | 71 | isUserLoggedIn () { |
61 | return this.authService.isLoggedIn() | 72 | return this.authService.isLoggedIn() |
62 | } | 73 | } |