aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/modal/quick-settings-modal.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/modal/quick-settings-modal.component.ts')
-rw-r--r--client/src/app/modal/quick-settings-modal.component.ts23
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 @@
1import { ReplaySubject } from 'rxjs' 1import { ReplaySubject, Subscription } from 'rxjs'
2import { filter } from 'rxjs/operators' 2import { filter } from 'rxjs/operators'
3import { Component, OnInit, ViewChild } from '@angular/core' 3import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
4import { ActivatedRoute, Router } from '@angular/router' 4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, AuthStatus, LocalStorageService, User, UserService } from '@app/core' 5import { AuthService, AuthStatus, LocalStorageService, User, UserService } from '@app/core'
6import { NgbModal } from '@ng-bootstrap/ng-bootstrap' 6import { 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})
13export class QuickSettingsModalComponent implements OnInit { 13export 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 }