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 { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
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
26 private route: ActivatedRoute,
27 private notifier: Notifier,
28 private authService: AuthService,
29 private videoChannelService: VideoChannelService,
30 private restExtractor: RestExtractor,
31 private hotkeysService: HotkeysService,
32 private screenService: ScreenService
36 this.routeSub = this.route.params
38 map(params => params[ 'videoChannelName' ]),
39 distinctUntilChanged(),
40 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
41 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
42 HttpStatusCode.BAD_REQUEST_400,
43 HttpStatusCode.NOT_FOUND_404
46 .subscribe(videoChannel => {
47 this.videoChannel = videoChannel
49 if (this.authService.isLoggedIn()) {
50 this.authService.userInformationLoaded
52 const channelUserId = this.videoChannel.ownerAccount.userId
53 this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
59 new Hotkey('S', (event: KeyboardEvent): boolean => {
60 this.subscribeButton.subscribed ?
61 this.subscribeButton.unsubscribe() :
62 this.subscribeButton.subscribe()
64 }, undefined, $localize`Subscribe to the account`)
66 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
69 { label: $localize`VIDEOS`, routerLink: 'videos' },
70 { label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' },
71 { label: $localize`ABOUT`, routerLink: 'about' }
76 if (this.routeSub) this.routeSub.unsubscribe()
79 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
82 get isInSmallView () {
83 return this.screenService.isInSmallView()
87 return this.authService.isLoggedIn()
91 if (!this.isUserLoggedIn()) return false
92 return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
95 activateCopiedMessage () {
96 this.notifier.success($localize`Username copied`)