]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts
Fix account/channel pages route subscription
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-videos / video-channel-videos.component.ts
CommitLineData
0626e7af
C
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
3import { Location } from '@angular/common'
4import { immutableAssign } from '@app/shared/misc/utils'
5import { NotificationsService } from 'angular2-notifications'
0626e7af
C
6import { AuthService } from '../../core/auth'
7import { ConfirmService } from '../../core/confirm'
8import { AbstractVideoList } from '../../shared/video/abstract-video-list'
9import { VideoService } from '../../shared/video/video.service'
170726f5
C
10import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
11import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
0bf1f265 12import { tap } from 'rxjs/operators'
b1d40cff 13import { I18n } from '@ngx-translate/i18n-polyfill'
734a5ceb 14import { Subscription } from 'rxjs'
0626e7af
C
15
16@Component({
170726f5 17 selector: 'my-video-channel-videos',
0626e7af
C
18 templateUrl: '../../shared/video/abstract-video-list.html',
19 styleUrls: [
20 '../../shared/video/abstract-video-list.scss',
170726f5 21 './video-channel-videos.component.scss'
0626e7af
C
22 ]
23})
170726f5 24export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
b1d40cff 25 titlePage: string
0626e7af 26 marginContent = false // Disable margin
170726f5 27 currentRoute = '/video-channel/videos'
0626e7af
C
28 loadOnInit = false
29
170726f5 30 private videoChannel: VideoChannel
734a5ceb 31 private videoChannelSub: Subscription
0626e7af
C
32
33 constructor (
34 protected router: Router,
35 protected route: ActivatedRoute,
36 protected authService: AuthService,
37 protected notificationsService: NotificationsService,
38 protected confirmService: ConfirmService,
39 protected location: Location,
b1d40cff 40 protected i18n: I18n,
170726f5 41 private videoChannelService: VideoChannelService,
0626e7af
C
42 private videoService: VideoService
43 ) {
44 super()
b1d40cff
C
45
46 this.titlePage = this.i18n('Published videos')
0626e7af
C
47 }
48
49 ngOnInit () {
50 super.ngOnInit()
51
170726f5 52 // Parent get the video channel for us
734a5ceb 53 this.videoChannelSub = this.videoChannelService.videoChannelLoaded
170726f5
C
54 .subscribe(videoChannel => {
55 this.videoChannel = videoChannel
56 this.currentRoute = '/video-channel/' + this.videoChannel.uuid + '/videos'
0626e7af 57
734a5ceb 58 this.reloadVideos()
0626e7af
C
59 this.generateSyndicationList()
60 })
61 }
62
63 ngOnDestroy () {
734a5ceb
C
64 if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
65
0626e7af
C
66 super.ngOnDestroy()
67 }
68
69 getVideosObservable (page: number) {
70 const newPagination = immutableAssign(this.pagination, { currentPage: page })
71
0bf1f265
C
72 return this.videoService
73 .getVideoChannelVideos(this.videoChannel, newPagination, this.sort)
b1d40cff
C
74 .pipe(
75 tap(({ totalVideos }) => {
25acef90 76 this.titlePage = this.i18n('Published {{totalVideos}} videos', { totalVideos })
b1d40cff
C
77 })
78 )
0626e7af
C
79 }
80
81 generateSyndicationList () {
170726f5 82 this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
0626e7af
C
83 }
84}