X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Bvideo-channels%2Fvideo-channels.component.ts;h=57c55d28673a20da2b21b04b3c38cad98ada39ae;hb=b34a444e291c8ec90b4c2c965f7d0d6904d1faa7;hp=09541b370e52febb413ae2853058a40dbb6f22e0;hpb=a51bad1accfade25916db0dadaeb879a182cf19b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+video-channels/video-channels.component.ts b/client/src/app/+video-channels/video-channels.component.ts index 09541b370..57c55d286 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, OnDestroy, OnInit } 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, distinctUntilChanged, map, switchMap } from 'rxjs/operators' +import { Subscription } from 'rxjs' @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() } }