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