]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+accounts/account-videos/account-videos.component.ts
Add ability to display all channel/account videos
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-videos / account-videos.component.ts
1 import { Subscription } from 'rxjs'
2 import { first, tap } from 'rxjs/operators'
3 import { Component, OnDestroy, OnInit } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
5 import { AuthService, ConfirmService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
6 import { immutableAssign } from '@app/helpers'
7 import { Account, AccountService, VideoService } from '@app/shared/shared-main'
8 import { AbstractVideoList } from '@app/shared/shared-video-miniature'
9 import { VideoFilter } from '@shared/models'
10
11 @Component({
12 selector: 'my-account-videos',
13 templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html',
14 styleUrls: [
15 '../../shared/shared-video-miniature/abstract-video-list.scss'
16 ]
17 })
18 export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
19 titlePage: string
20 loadOnInit = false
21
22 filter: VideoFilter = null
23
24 private account: Account
25 private accountSub: Subscription
26
27 constructor (
28 protected router: Router,
29 protected serverService: ServerService,
30 protected route: ActivatedRoute,
31 protected authService: AuthService,
32 protected userService: UserService,
33 protected notifier: Notifier,
34 protected confirmService: ConfirmService,
35 protected screenService: ScreenService,
36 protected storageService: LocalStorageService,
37 private accountService: AccountService,
38 private videoService: VideoService
39 ) {
40 super()
41 }
42
43 ngOnInit () {
44 super.ngOnInit()
45
46 this.enableAllFilterIfPossible()
47
48 // Parent get the account for us
49 this.accountSub = this.accountService.accountLoaded
50 .pipe(first())
51 .subscribe(account => {
52 this.account = account
53
54 this.reloadVideos()
55 this.generateSyndicationList()
56 })
57 }
58
59 ngOnDestroy () {
60 if (this.accountSub) this.accountSub.unsubscribe()
61
62 super.ngOnDestroy()
63 }
64
65 getVideosObservable (page: number) {
66 const newPagination = immutableAssign(this.pagination, { currentPage: page })
67 const options = {
68 account: this.account,
69 videoPagination: newPagination,
70 sort: this.sort,
71 nsfwPolicy: this.nsfwPolicy,
72 videoFilter: this.filter
73 }
74
75 return this.videoService
76 .getAccountVideos(options)
77 .pipe(
78 tap(({ total }) => {
79 this.titlePage = $localize`Published ${total} videos`
80 })
81 )
82 }
83
84 toggleModerationDisplay () {
85 this.filter = this.buildLocalFilter(this.filter, null)
86
87 this.reloadVideos()
88 }
89
90 generateSyndicationList () {
91 this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id)
92 }
93 }