1
0
Fork 0
peertube/client/src/app/+video-channels/video-channels.component.ts

66 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
2018-04-25 14:56:13 +00: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 09:35:01 +00:00
import { RestExtractor } from '@app/shared'
2018-06-18 09:02:24 +00:00
import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
import { Subscription } from 'rxjs'
2018-08-30 12:58:00 +00:00
import { AuthService } from '@app/core'
import { Hotkey, HotkeysService } from 'angular2-hotkeys'
import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component'
2018-10-03 08:11:26 +00:00
import { I18n } from '@ngx-translate/i18n-polyfill'
2018-04-25 14:56:13 +00:00
@Component({
templateUrl: './video-channels.component.html',
styleUrls: [ './video-channels.component.scss' ]
})
export class VideoChannelsComponent implements OnInit, OnDestroy {
@ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
2018-04-25 14:56:13 +00:00
videoChannel: VideoChannel
hotkeys: Hotkey[]
2018-04-25 14:56:13 +00:00
private routeSub: Subscription
2018-04-25 14:56:13 +00:00
constructor (
2018-10-03 08:11:26 +00:00
private i18n: I18n,
2018-04-25 14:56:13 +00:00
private route: ActivatedRoute,
2018-08-30 12:58:00 +00:00
private authService: AuthService,
2018-05-31 09:35:01 +00:00
private videoChannelService: VideoChannelService,
private restExtractor: RestExtractor,
private hotkeysService: HotkeysService
) { }
2018-04-25 14:56:13 +00:00
ngOnInit () {
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.hotkeys = [
new Hotkey('S', (event: KeyboardEvent): boolean => {
this.subscribeButton.subscribed ?
this.subscribeButton.unsubscribe() :
this.subscribeButton.subscribe()
return false
2018-10-03 08:11:26 +00:00
}, undefined, this.i18n('Subscribe to the account'))
]
if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
}
2018-04-25 14:56:13 +00:00
ngOnDestroy () {
if (this.routeSub) this.routeSub.unsubscribe()
// Unbind hotkeys
if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
2018-04-25 14:56:13 +00:00
}
2018-08-30 12:58:00 +00:00
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
2018-04-25 14:56:13 +00:00
}