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