2018-06-18 04:02:24 -05:00
|
|
|
import { Component, OnDestroy, OnInit } from '@angular/core'
|
2018-04-25 09:56:13 -05:00
|
|
|
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'
|
2018-05-31 04:35:01 -05:00
|
|
|
import { RestExtractor } from '@app/shared'
|
2018-06-18 04:02:24 -05:00
|
|
|
import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
|
|
|
|
import { Subscription } from 'rxjs'
|
2018-04-25 09:56:13 -05:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: './video-channels.component.html',
|
|
|
|
styleUrls: [ './video-channels.component.scss' ]
|
|
|
|
})
|
2018-06-07 04:19:26 -05:00
|
|
|
export class VideoChannelsComponent implements OnInit, OnDestroy {
|
2018-04-25 09:56:13 -05:00
|
|
|
videoChannel: VideoChannel
|
|
|
|
|
2018-06-07 04:19:26 -05:00
|
|
|
private routeSub: Subscription
|
|
|
|
|
2018-04-25 09:56:13 -05:00
|
|
|
constructor (
|
|
|
|
private route: ActivatedRoute,
|
2018-05-31 04:35:01 -05:00
|
|
|
private videoChannelService: VideoChannelService,
|
|
|
|
private restExtractor: RestExtractor
|
2018-06-07 04:19:26 -05:00
|
|
|
) { }
|
2018-04-25 09:56:13 -05:00
|
|
|
|
|
|
|
ngOnInit () {
|
2018-06-07 04:19:26 -05:00
|
|
|
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)
|
|
|
|
|
|
|
|
}
|
2018-04-25 09:56:13 -05:00
|
|
|
|
2018-06-07 04:19:26 -05:00
|
|
|
ngOnDestroy () {
|
|
|
|
if (this.routeSub) this.routeSub.unsubscribe()
|
2018-04-25 09:56:13 -05:00
|
|
|
}
|
|
|
|
}
|