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 | |
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')
3 files changed, 51 insertions, 29 deletions
diff --git a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts index ee3a6c73e..42259129c 100644 --- a/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts +++ b/client/src/app/+videos/+video-watch/shared/recommendations/recommended-videos.component.ts | |||
@@ -58,7 +58,6 @@ export class RecommendedVideosComponent implements OnInit, OnChanges, OnDestroy | |||
58 | .subscribe(user => { | 58 | .subscribe(user => { |
59 | this.user = user | 59 | this.user = user |
60 | this.autoPlayNextVideo = user.autoPlayNextVideo | 60 | this.autoPlayNextVideo = user.autoPlayNextVideo |
61 | console.log(this.autoPlayNextVideo) | ||
62 | }) | 61 | }) |
63 | } | 62 | } |
64 | 63 | ||
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 @@ | |||
1 | import { HotkeysService } from 'angular2-hotkeys' | 1 | import { HotkeysService } from 'angular2-hotkeys' |
2 | import * as debug from 'debug' | 2 | import * as debug from 'debug' |
3 | import { switchMap } from 'rxjs/operators' | 3 | import { forkJoin, Subscription } from 'rxjs' |
4 | import { first, switchMap } from 'rxjs/operators' | ||
4 | import { ViewportScroller } from '@angular/common' | 5 | import { ViewportScroller } from '@angular/common' |
5 | import { Component, OnInit, ViewChild } from '@angular/core' | 6 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' |
6 | import { Router } from '@angular/router' | 7 | import { Router } from '@angular/router' |
7 | import { | 8 | import { |
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 | }) |
33 | export class MenuComponent implements OnInit { | 34 | export 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 | ||
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 | } |