From 734a5ceb3d04088743d72babcb9b05e6142043f6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 7 Jun 2018 11:19:26 +0200 Subject: Fix account/channel pages route subscription --- .../video-channel-about.component.ts | 13 ++++++++--- .../video-channel-videos.component.ts | 8 +++++-- .../+video-channels/video-channels.component.ts | 27 +++++++++++++++------- 3 files changed, 35 insertions(+), 13 deletions(-) (limited to 'client/src/app/+video-channels') diff --git a/client/src/app/+video-channels/video-channel-about/video-channel-about.component.ts b/client/src/app/+video-channels/video-channel-about/video-channel-about.component.ts index c5fd442c6..dc0893962 100644 --- a/client/src/app/+video-channels/video-channel-about/video-channel-about.component.ts +++ b/client/src/app/+video-channels/video-channel-about/video-channel-about.component.ts @@ -1,17 +1,20 @@ -import { Component, OnInit } from '@angular/core' +import { Component, OnDestroy, OnInit } from '@angular/core' import { ActivatedRoute } from '@angular/router' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { I18n } from '@ngx-translate/i18n-polyfill' +import { Subscription } from 'rxjs' @Component({ selector: 'my-video-channel-about', templateUrl: './video-channel-about.component.html', styleUrls: [ './video-channel-about.component.scss' ] }) -export class VideoChannelAboutComponent implements OnInit { +export class VideoChannelAboutComponent implements OnInit, OnDestroy { videoChannel: VideoChannel + private videoChannelSub: Subscription + constructor ( private route: ActivatedRoute, private i18n: I18n, @@ -20,10 +23,14 @@ export class VideoChannelAboutComponent implements OnInit { ngOnInit () { // Parent get the video channel for us - this.videoChannelService.videoChannelLoaded + this.videoChannelSub = this.videoChannelService.videoChannelLoaded .subscribe(videoChannel => this.videoChannel = videoChannel) } + ngOnDestroy () { + if (this.videoChannelSub) this.videoChannelSub.unsubscribe() + } + getVideoChannelDescription () { if (this.videoChannel.description) return this.videoChannel.description diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts index 28c591039..2d3f66994 100644 --- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts +++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts @@ -11,6 +11,7 @@ import { VideoChannelService } from '@app/shared/video-channel/video-channel.ser import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { tap } from 'rxjs/operators' import { I18n } from '@ngx-translate/i18n-polyfill' +import { Subscription } from 'rxjs' @Component({ selector: 'my-video-channel-videos', @@ -27,6 +28,7 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On loadOnInit = false private videoChannel: VideoChannel + private videoChannelSub: Subscription constructor ( protected router: Router, @@ -48,17 +50,19 @@ export class VideoChannelVideosComponent extends AbstractVideoList implements On super.ngOnInit() // Parent get the video channel for us - this.videoChannelService.videoChannelLoaded + this.videoChannelSub = this.videoChannelService.videoChannelLoaded .subscribe(videoChannel => { this.videoChannel = videoChannel this.currentRoute = '/video-channel/' + this.videoChannel.uuid + '/videos' - this.loadMoreVideos(this.pagination.currentPage) + this.reloadVideos() this.generateSyndicationList() }) } ngOnDestroy () { + if (this.videoChannelSub) this.videoChannelSub.unsubscribe() + super.ngOnDestroy() } diff --git a/client/src/app/+video-channels/video-channels.component.ts b/client/src/app/+video-channels/video-channels.component.ts index 09541b370..cd0463859 100644 --- a/client/src/app/+video-channels/video-channels.component.ts +++ b/client/src/app/+video-channels/video-channels.component.ts @@ -1,28 +1,39 @@ -import { Component, OnInit } from '@angular/core' +import { Component, OnInit, OnDestroy } from '@angular/core' import { ActivatedRoute } from '@angular/router' import { VideoChannel } from '@app/shared/video-channel/video-channel.model' import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' import { RestExtractor } from '@app/shared' -import { catchError } from 'rxjs/operators' +import { catchError, switchMap, map, distinctUntilChanged } from 'rxjs/operators' +import { Subscription } from 'rxjs/Subscription' @Component({ templateUrl: './video-channels.component.html', styleUrls: [ './video-channels.component.scss' ] }) -export class VideoChannelsComponent implements OnInit { +export class VideoChannelsComponent implements OnInit, OnDestroy { videoChannel: VideoChannel + private routeSub: Subscription + constructor ( private route: ActivatedRoute, private videoChannelService: VideoChannelService, private restExtractor: RestExtractor - ) {} + ) { } ngOnInit () { - const videoChannelId = this.route.snapshot.params['videoChannelId'] + this.routeSub = this.route.params + .pipe( + map(params => params[ 'videoChannelId' ]), + distinctUntilChanged(), + switchMap(videoChannelId => this.videoChannelService.getVideoChannel(videoChannelId)), + catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) + ) + .subscribe(videoChannel => this.videoChannel = videoChannel) + + } - this.videoChannelService.getVideoChannel(videoChannelId) - .pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))) - .subscribe(videoChannel => this.videoChannel = videoChannel) + ngOnDestroy () { + if (this.routeSub) this.routeSub.unsubscribe() } } -- cgit v1.2.3