aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/menu/menu.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/menu/menu.component.ts')
-rw-r--r--client/src/app/menu/menu.component.ts56
1 files changed, 34 insertions, 22 deletions
diff --git a/client/src/app/menu/menu.component.ts b/client/src/app/menu/menu.component.ts
index 21354e52d..896c824b8 100644
--- a/client/src/app/menu/menu.component.ts
+++ b/client/src/app/menu/menu.component.ts
@@ -1,8 +1,9 @@
1import { HotkeysService } from 'angular2-hotkeys' 1import { HotkeysService } from 'angular2-hotkeys'
2import * as debug from 'debug' 2import * as debug from 'debug'
3import { switchMap } from 'rxjs/operators' 3import { forkJoin, Subscription } from 'rxjs'
4import { first, switchMap } from 'rxjs/operators'
4import { ViewportScroller } from '@angular/common' 5import { ViewportScroller } from '@angular/common'
5import { Component, OnInit, ViewChild } from '@angular/core' 6import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
6import { Router } from '@angular/router' 7import { Router } from '@angular/router'
7import { 8import {
8 AuthService, 9 AuthService,
@@ -30,7 +31,7 @@ const debugLogger = debug('peertube:menu:MenuComponent')
30 templateUrl: './menu.component.html', 31 templateUrl: './menu.component.html',
31 styleUrls: [ './menu.component.scss' ] 32 styleUrls: [ './menu.component.scss' ]
32}) 33})
33export class MenuComponent implements OnInit { 34export class MenuComponent implements OnInit, OnDestroy {
34 @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent 35 @ViewChild('languageChooserModal', { static: true }) languageChooserModal: LanguageChooserComponent
35 @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent 36 @ViewChild('quickSettingsModal', { static: true }) quickSettingsModal: QuickSettingsModalComponent
36 @ViewChild('dropdown') dropdown: NgbDropdown 37 @ViewChild('dropdown') dropdown: NgbDropdown
@@ -62,6 +63,11 @@ export class MenuComponent implements OnInit {
62 [UserRight.MANAGE_CONFIGURATION]: '/admin/config' 63 [UserRight.MANAGE_CONFIGURATION]: '/admin/config'
63 } 64 }
64 65
66 private languagesSub: Subscription
67 private modalSub: Subscription
68 private hotkeysSub: Subscription
69 private authSub: Subscription
70
65 constructor ( 71 constructor (
66 private viewportScroller: ViewportScroller, 72 private viewportScroller: ViewportScroller,
67 private authService: AuthService, 73 private authService: AuthService,
@@ -102,37 +108,43 @@ export class MenuComponent implements OnInit {
102 this.updateUserState() 108 this.updateUserState()
103 this.buildMenuSections() 109 this.buildMenuSections()
104 110
105 this.authService.loginChangedSource.subscribe( 111 this.authSub = this.authService.loginChangedSource.subscribe(status => {
106 status => { 112 if (status === AuthStatus.LoggedIn) {
107 if (status === AuthStatus.LoggedIn) { 113 this.isLoggedIn = true
108 this.isLoggedIn = true 114 } else if (status === AuthStatus.LoggedOut) {
109 } else if (status === AuthStatus.LoggedOut) { 115 this.isLoggedIn = false
110 this.isLoggedIn = false
111 }
112
113 this.updateUserState()
114 this.buildMenuSections()
115 } 116 }
116 )
117 117
118 this.hotkeysService.cheatSheetToggle 118 this.updateUserState()
119 this.buildMenuSections()
120 })
121
122 this.hotkeysSub = this.hotkeysService.cheatSheetToggle
119 .subscribe(isOpen => this.helpVisible = isOpen) 123 .subscribe(isOpen => this.helpVisible = isOpen)
120 124
121 this.serverService.getVideoLanguages() 125 this.languagesSub = forkJoin([
122 .subscribe(languages => { 126 this.serverService.getVideoLanguages(),
123 this.languages = languages 127 this.authService.userInformationLoaded.pipe(first())
128 ]).subscribe(([ languages ]) => {
129 this.languages = languages
124 130
125 this.authService.userInformationLoaded 131 this.buildUserLanguages()
126 .subscribe(() => this.buildUserLanguages()) 132 })
127 })
128 133
129 this.serverService.getConfig() 134 this.serverService.getConfig()
130 .subscribe(config => this.serverConfig = config) 135 .subscribe(config => this.serverConfig = config)
131 136
132 this.modalService.openQuickSettingsSubject 137 this.modalSub = this.modalService.openQuickSettingsSubject
133 .subscribe(() => this.openQuickSettings()) 138 .subscribe(() => this.openQuickSettings())
134 } 139 }
135 140
141 ngOnDestroy () {
142 if (this.modalSub) this.modalSub.unsubscribe()
143 if (this.languagesSub) this.languagesSub.unsubscribe()
144 if (this.hotkeysSub) this.hotkeysSub.unsubscribe()
145 if (this.authSub) this.authSub.unsubscribe()
146 }
147
136 isRegistrationAllowed () { 148 isRegistrationAllowed () {
137 if (!this.serverConfig) return false 149 if (!this.serverConfig) return false
138 150