diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-07 11:19:26 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-07 11:19:26 +0200 |
commit | 734a5ceb3d04088743d72babcb9b05e6142043f6 (patch) | |
tree | 965bfbd0bf930cf4cc9568a5dc801c4e3909a1b4 /client/src/app/+video-channels/video-channels.component.ts | |
parent | cc69c8db39f48b1053c246458541ccc406228711 (diff) | |
download | PeerTube-734a5ceb3d04088743d72babcb9b05e6142043f6.tar.gz PeerTube-734a5ceb3d04088743d72babcb9b05e6142043f6.tar.zst PeerTube-734a5ceb3d04088743d72babcb9b05e6142043f6.zip |
Fix account/channel pages route subscription
Diffstat (limited to 'client/src/app/+video-channels/video-channels.component.ts')
-rw-r--r-- | client/src/app/+video-channels/video-channels.component.ts | 27 |
1 files changed, 19 insertions, 8 deletions
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 @@ | |||
1 | import { Component, OnInit } from '@angular/core' | 1 | import { Component, OnInit, OnDestroy } from '@angular/core' |
2 | import { ActivatedRoute } from '@angular/router' | 2 | import { ActivatedRoute } from '@angular/router' |
3 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | 3 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' |
4 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | 4 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
5 | import { RestExtractor } from '@app/shared' | 5 | import { RestExtractor } from '@app/shared' |
6 | import { catchError } from 'rxjs/operators' | 6 | import { catchError, switchMap, map, distinctUntilChanged } from 'rxjs/operators' |
7 | import { Subscription } from 'rxjs/Subscription' | ||
7 | 8 | ||
8 | @Component({ | 9 | @Component({ |
9 | templateUrl: './video-channels.component.html', | 10 | templateUrl: './video-channels.component.html', |
10 | styleUrls: [ './video-channels.component.scss' ] | 11 | styleUrls: [ './video-channels.component.scss' ] |
11 | }) | 12 | }) |
12 | export class VideoChannelsComponent implements OnInit { | 13 | export class VideoChannelsComponent implements OnInit, OnDestroy { |
13 | videoChannel: VideoChannel | 14 | videoChannel: VideoChannel |
14 | 15 | ||
16 | private routeSub: Subscription | ||
17 | |||
15 | constructor ( | 18 | constructor ( |
16 | private route: ActivatedRoute, | 19 | private route: ActivatedRoute, |
17 | private videoChannelService: VideoChannelService, | 20 | private videoChannelService: VideoChannelService, |
18 | private restExtractor: RestExtractor | 21 | private restExtractor: RestExtractor |
19 | ) {} | 22 | ) { } |
20 | 23 | ||
21 | ngOnInit () { | 24 | ngOnInit () { |
22 | const videoChannelId = this.route.snapshot.params['videoChannelId'] | 25 | this.routeSub = this.route.params |
26 | .pipe( | ||
27 | map(params => params[ 'videoChannelId' ]), | ||
28 | distinctUntilChanged(), | ||
29 | switchMap(videoChannelId => this.videoChannelService.getVideoChannel(videoChannelId)), | ||
30 | catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ])) | ||
31 | ) | ||
32 | .subscribe(videoChannel => this.videoChannel = videoChannel) | ||
33 | |||
34 | } | ||
23 | 35 | ||
24 | this.videoChannelService.getVideoChannel(videoChannelId) | 36 | ngOnDestroy () { |
25 | .pipe(catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))) | 37 | if (this.routeSub) this.routeSub.unsubscribe() |
26 | .subscribe(videoChannel => this.videoChannel = videoChannel) | ||
27 | } | 38 | } |
28 | } | 39 | } |