]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channels.component.ts
Add support button in channel page
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channels.component.ts
CommitLineData
67ed6552
C
1import { Hotkey, HotkeysService } from 'angular2-hotkeys'
2import { Subscription } from 'rxjs'
3import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
20d21199 4import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
170726f5 5import { ActivatedRoute } from '@angular/router'
60c35932
C
6import { AuthService, MarkdownService, Notifier, RestExtractor, ScreenService } from '@app/core'
7import { ListOverflowItem, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
100d9ce2 8import { SupportModalComponent } from '@app/shared/shared-support-modal'
67ed6552 9import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
f2eb23cd 10import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
170726f5
C
11
12@Component({
13 templateUrl: './video-channels.component.html',
14 styleUrls: [ './video-channels.component.scss' ]
15})
734a5ceb 16export class VideoChannelsComponent implements OnInit, OnDestroy {
2f5d2ec5 17 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
100d9ce2 18 @ViewChild('supportModal') supportModal: SupportModalComponent
20d21199 19
170726f5 20 videoChannel: VideoChannel
20d21199 21 hotkeys: Hotkey[]
24e7916c 22 links: ListOverflowItem[] = []
fef213ca 23 isChannelManageable = false
170726f5 24
60c35932
C
25 channelVideosCount: number
26 ownerDescriptionHTML = ''
27 channelDescriptionHTML = ''
28 channelDescriptionExpanded = false
29
734a5ceb
C
30 private routeSub: Subscription
31
170726f5
C
32 constructor (
33 private route: ActivatedRoute,
a0dedc02 34 private notifier: Notifier,
2d3741d6 35 private authService: AuthService,
a51bad1a 36 private videoChannelService: VideoChannelService,
60c35932 37 private videoService: VideoService,
20d21199 38 private restExtractor: RestExtractor,
937b7a6a 39 private hotkeysService: HotkeysService,
60c35932
C
40 private screenService: ScreenService,
41 private markdown: MarkdownService
734a5ceb 42 ) { }
170726f5
C
43
44 ngOnInit () {
734a5ceb
C
45 this.routeSub = this.route.params
46 .pipe(
2f1548fd 47 map(params => params[ 'videoChannelName' ]),
734a5ceb 48 distinctUntilChanged(),
2f1548fd 49 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
ab398a05 50 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
f2eb23cd
RK
51 HttpStatusCode.BAD_REQUEST_400,
52 HttpStatusCode.NOT_FOUND_404
53 ]))
734a5ceb 54 )
60c35932
C
55 .subscribe(async videoChannel => {
56 this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.description)
57 this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.ownerAccount.description)
58
59 // After the markdown renderer to avoid layout changes
fef213ca
C
60 this.videoChannel = videoChannel
61
60c35932 62 this.loadChannelVideosCount()
fef213ca 63 })
734a5ceb 64
20d21199
RK
65 this.hotkeys = [
66 new Hotkey('S', (event: KeyboardEvent): boolean => {
67 this.subscribeButton.subscribed ?
68 this.subscribeButton.unsubscribe() :
69 this.subscribeButton.subscribe()
70 return false
66357162 71 }, undefined, $localize`Subscribe to the account`)
20d21199
RK
72 ]
73 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
24e7916c
RK
74
75 this.links = [
66357162 76 { label: $localize`VIDEOS`, routerLink: 'videos' },
60c35932 77 { label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' }
24e7916c 78 ]
734a5ceb 79 }
170726f5 80
734a5ceb
C
81 ngOnDestroy () {
82 if (this.routeSub) this.routeSub.unsubscribe()
20d21199
RK
83
84 // Unbind hotkeys
85 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
170726f5 86 }
2d3741d6 87
60c35932 88 isInSmallView () {
937b7a6a
RK
89 return this.screenService.isInSmallView()
90 }
91
2d3741d6
C
92 isUserLoggedIn () {
93 return this.authService.isLoggedIn()
94 }
a0dedc02 95
60c35932 96 isManageable () {
aa0f1963 97 if (!this.isUserLoggedIn()) return false
60c35932 98
67264e06 99 return this.videoChannel?.ownerAccount.userId === this.authService.getUser().id
aa0f1963
RK
100 }
101
a0dedc02 102 activateCopiedMessage () {
66357162 103 this.notifier.success($localize`Username copied`)
a0dedc02 104 }
60c35932 105
100d9ce2
C
106 showSupportModal () {
107 this.supportModal.show()
108 }
109
60c35932
C
110 private loadChannelVideosCount () {
111 this.videoService.getVideoChannelVideos({
112 videoChannel: this.videoChannel,
113 videoPagination: {
114 currentPage: 1,
115 itemsPerPage: 0
116 },
117 sort: '-publishedAt'
118 }).subscribe(res => this.channelVideosCount = res.total)
119 }
170726f5 120}