]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channels.component.ts
improve likes-dislikes bar usability
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channels.component.ts
CommitLineData
20d21199 1import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
170726f5
C
2import { ActivatedRoute } from '@angular/router'
3import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
4import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
a51bad1a 5import { RestExtractor } from '@app/shared'
4d089429
C
6import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
7import { Subscription } from 'rxjs'
2d3741d6 8import { AuthService } from '@app/core'
20d21199
RK
9import { Hotkey, HotkeysService } from 'angular2-hotkeys'
10import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component'
e33f888b 11import { I18n } from '@ngx-translate/i18n-polyfill'
170726f5
C
12
13@Component({
14 templateUrl: './video-channels.component.html',
15 styleUrls: [ './video-channels.component.scss' ]
16})
734a5ceb 17export class VideoChannelsComponent implements OnInit, OnDestroy {
f36da21e 18 @ViewChild('subscribeButton', { static: false }) subscribeButton: SubscribeButtonComponent
20d21199 19
170726f5 20 videoChannel: VideoChannel
20d21199 21 hotkeys: Hotkey[]
170726f5 22
734a5ceb
C
23 private routeSub: Subscription
24
170726f5 25 constructor (
e33f888b 26 private i18n: I18n,
170726f5 27 private route: ActivatedRoute,
2d3741d6 28 private authService: AuthService,
a51bad1a 29 private videoChannelService: VideoChannelService,
20d21199
RK
30 private restExtractor: RestExtractor,
31 private hotkeysService: HotkeysService
734a5ceb 32 ) { }
170726f5
C
33
34 ngOnInit () {
734a5ceb
C
35 this.routeSub = this.route.params
36 .pipe(
2f1548fd 37 map(params => params[ 'videoChannelName' ]),
734a5ceb 38 distinctUntilChanged(),
2f1548fd 39 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
734a5ceb
C
40 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
41 )
42 .subscribe(videoChannel => this.videoChannel = videoChannel)
43
20d21199
RK
44 this.hotkeys = [
45 new Hotkey('S', (event: KeyboardEvent): boolean => {
46 this.subscribeButton.subscribed ?
47 this.subscribeButton.unsubscribe() :
48 this.subscribeButton.subscribe()
49 return false
e33f888b 50 }, undefined, this.i18n('Subscribe to the account'))
20d21199
RK
51 ]
52 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
734a5ceb 53 }
170726f5 54
734a5ceb
C
55 ngOnDestroy () {
56 if (this.routeSub) this.routeSub.unsubscribe()
20d21199
RK
57
58 // Unbind hotkeys
59 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
170726f5 60 }
2d3741d6
C
61
62 isUserLoggedIn () {
63 return this.authService.isLoggedIn()
64 }
170726f5 65}