1 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
2 import { Subscription } from 'rxjs'
3 import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
4 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
5 import { ActivatedRoute } from '@angular/router'
6 import { AuthService, Notifier, RestExtractor, ScreenService } from '@app/core'
7 import { ListOverflowItem, VideoChannel, VideoChannelService } from '@app/shared/shared-main'
8 import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
9 import { I18n } from '@ngx-translate/i18n-polyfill'
12 templateUrl: './video-channels.component.html',
13 styleUrls: [ './video-channels.component.scss' ]
15 export class VideoChannelsComponent implements OnInit, OnDestroy {
16 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
18 videoChannel: VideoChannel
20 links: ListOverflowItem[] = []
21 isChannelManageable = false
23 private routeSub: Subscription
27 private route: ActivatedRoute,
28 private notifier: Notifier,
29 private authService: AuthService,
30 private videoChannelService: VideoChannelService,
31 private restExtractor: RestExtractor,
32 private hotkeysService: HotkeysService,
33 private screenService: ScreenService
37 this.routeSub = this.route.params
39 map(params => params[ 'videoChannelName' ]),
40 distinctUntilChanged(),
41 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
42 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
44 .subscribe(videoChannel => {
45 this.videoChannel = videoChannel
47 if (this.authService.isLoggedIn()) {
48 this.authService.userInformationLoaded
50 const channelUserId = this.videoChannel.ownerAccount.userId
51 this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
57 new Hotkey('S', (event: KeyboardEvent): boolean => {
58 this.subscribeButton.subscribed ?
59 this.subscribeButton.unsubscribe() :
60 this.subscribeButton.subscribe()
62 }, undefined, this.i18n('Subscribe to the account'))
64 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
67 { label: this.i18n('VIDEOS'), routerLink: 'videos' },
68 { label: this.i18n('VIDEO PLAYLISTS'), routerLink: 'video-playlists' },
69 { label: this.i18n('ABOUT'), routerLink: 'about' }
74 if (this.routeSub) this.routeSub.unsubscribe()
77 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
80 get isInSmallView () {
81 return this.screenService.isInSmallView()
85 return this.authService.isLoggedIn()
89 if (!this.isUserLoggedIn()) return false
90 return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
93 activateCopiedMessage () {
94 this.notifier.success(this.i18n('Username copied'))