]>
Commit | Line | Data |
---|---|---|
4d089429 | 1 | import { Component, OnDestroy, OnInit } from '@angular/core' |
170726f5 C |
2 | import { ActivatedRoute } from '@angular/router' |
3 | import { VideoChannel } from '@app/shared/video-channel/video-channel.model' | |
4 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | |
a51bad1a | 5 | import { RestExtractor } from '@app/shared' |
4d089429 C |
6 | import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators' |
7 | import { Subscription } from 'rxjs' | |
170726f5 C |
8 | |
9 | @Component({ | |
10 | templateUrl: './video-channels.component.html', | |
11 | styleUrls: [ './video-channels.component.scss' ] | |
12 | }) | |
734a5ceb | 13 | export class VideoChannelsComponent implements OnInit, OnDestroy { |
170726f5 C |
14 | videoChannel: VideoChannel |
15 | ||
734a5ceb C |
16 | private routeSub: Subscription |
17 | ||
170726f5 C |
18 | constructor ( |
19 | private route: ActivatedRoute, | |
a51bad1a C |
20 | private videoChannelService: VideoChannelService, |
21 | private restExtractor: RestExtractor | |
734a5ceb | 22 | ) { } |
170726f5 C |
23 | |
24 | ngOnInit () { | |
734a5ceb C |
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 | } | |
170726f5 | 35 | |
734a5ceb C |
36 | ngOnDestroy () { |
37 | if (this.routeSub) this.routeSub.unsubscribe() | |
170726f5 C |
38 | } |
39 | } |