]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channels.component.ts
Add ListOverflow component to prevent sub-menu overflow
[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'
fef213ca 6import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'
4d089429 7import { Subscription } from 'rxjs'
a0dedc02 8import { AuthService, Notifier } 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'
24e7916c 12import { ListOverflowItem } from '@app/shared/misc/list-overflow.component'
170726f5
C
13
14@Component({
15 templateUrl: './video-channels.component.html',
16 styleUrls: [ './video-channels.component.scss' ]
17})
734a5ceb 18export class VideoChannelsComponent implements OnInit, OnDestroy {
2f5d2ec5 19 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
20d21199 20
170726f5 21 videoChannel: VideoChannel
20d21199 22 hotkeys: Hotkey[]
24e7916c 23 links: ListOverflowItem[] = []
fef213ca 24 isChannelManageable = false
170726f5 25
734a5ceb
C
26 private routeSub: Subscription
27
170726f5 28 constructor (
e33f888b 29 private i18n: I18n,
170726f5 30 private route: ActivatedRoute,
a0dedc02 31 private notifier: Notifier,
2d3741d6 32 private authService: AuthService,
a51bad1a 33 private videoChannelService: VideoChannelService,
20d21199
RK
34 private restExtractor: RestExtractor,
35 private hotkeysService: HotkeysService
734a5ceb 36 ) { }
170726f5
C
37
38 ngOnInit () {
734a5ceb
C
39 this.routeSub = this.route.params
40 .pipe(
2f1548fd 41 map(params => params[ 'videoChannelName' ]),
734a5ceb 42 distinctUntilChanged(),
2f1548fd 43 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
734a5ceb
C
44 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
45 )
fef213ca
C
46 .subscribe(videoChannel => {
47 this.videoChannel = videoChannel
48
49 if (this.authService.isLoggedIn()) {
50 this.authService.userInformationLoaded
51 .subscribe(() => {
52 const channelUserId = this.videoChannel.ownerAccount.userId
53 this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
54 })
55 }
56 })
734a5ceb 57
20d21199
RK
58 this.hotkeys = [
59 new Hotkey('S', (event: KeyboardEvent): boolean => {
60 this.subscribeButton.subscribed ?
61 this.subscribeButton.unsubscribe() :
62 this.subscribeButton.subscribe()
63 return false
e33f888b 64 }, undefined, this.i18n('Subscribe to the account'))
20d21199
RK
65 ]
66 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
24e7916c
RK
67
68 this.links = [
69 { label: this.i18n('Videos'), routerLink: 'videos' },
70 { label: this.i18n('Video playlists'), routerLink: 'video-playlists' },
71 { label: this.i18n('About'), routerLink: 'about' }
72 ]
734a5ceb 73 }
170726f5 74
734a5ceb
C
75 ngOnDestroy () {
76 if (this.routeSub) this.routeSub.unsubscribe()
20d21199
RK
77
78 // Unbind hotkeys
79 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
170726f5 80 }
2d3741d6
C
81
82 isUserLoggedIn () {
83 return this.authService.isLoggedIn()
84 }
a0dedc02 85
aa0f1963
RK
86 get isManageable () {
87 if (!this.isUserLoggedIn()) return false
88 return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
89 }
90
a0dedc02
RK
91 activateCopiedMessage () {
92 this.notifier.success(this.i18n('Username copied'))
93 }
170726f5 94}