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'
11 templateUrl: './video-channels.component.html',
12 styleUrls: [ './video-channels.component.scss' ]
14 export class VideoChannelsComponent implements OnInit, OnDestroy {
15 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
17 videoChannel: VideoChannel
19 links: ListOverflowItem[] = []
20 isChannelManageable = false
22 private routeSub: Subscription
25 private route: ActivatedRoute,
26 private notifier: Notifier,
27 private authService: AuthService,
28 private videoChannelService: VideoChannelService,
29 private restExtractor: RestExtractor,
30 private hotkeysService: HotkeysService,
31 private screenService: ScreenService
35 this.routeSub = this.route.params
37 map(params => params[ 'videoChannelName' ]),
38 distinctUntilChanged(),
39 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
40 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
42 .subscribe(videoChannel => {
43 this.videoChannel = videoChannel
45 if (this.authService.isLoggedIn()) {
46 this.authService.userInformationLoaded
48 const channelUserId = this.videoChannel.ownerAccount.userId
49 this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
55 new Hotkey('S', (event: KeyboardEvent): boolean => {
56 this.subscribeButton.subscribed ?
57 this.subscribeButton.unsubscribe() :
58 this.subscribeButton.subscribe()
60 }, undefined, $localize`Subscribe to the account`)
62 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
65 { label: $localize`VIDEOS`, routerLink: 'videos' },
66 { label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' },
67 { label: $localize`ABOUT`, routerLink: 'about' }
72 if (this.routeSub) this.routeSub.unsubscribe()
75 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
78 get isInSmallView () {
79 return this.screenService.isInSmallView()
83 return this.authService.isLoggedIn()
87 if (!this.isUserLoggedIn()) return false
88 return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
91 activateCopiedMessage () {
92 this.notifier.success($localize`Username copied`)