]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+video-channels/video-channels.component.ts
Fix account/channel pages route subscription
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channels.component.ts
index 09541b370e52febb413ae2853058a40dbb6f22e0..cd04638596b1d4d8dc56f4d8d1b3511853b2d993 100644 (file)
@@ -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()
   }
 }