]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+accounts/account-videos/account-videos.component.ts
Refactor video miniatures
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-videos / account-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 { Account } from '@app/shared/account/account.model'
9 import { AccountService } from '@app/shared/account/account.service'
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-account-videos',
18 templateUrl: '../../shared/video/abstract-video-list.html',
19 styleUrls: [
20 '../../shared/video/abstract-video-list.scss',
21 './account-videos.component.scss'
22 ]
23 })
24 export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
25 titlePage: string
26 loadOnInit = false
27
28 private account: Account
29 private accountSub: Subscription
30
31 constructor (
32 protected router: Router,
33 protected serverService: ServerService,
34 protected route: ActivatedRoute,
35 protected authService: AuthService,
36 protected notifier: Notifier,
37 protected confirmService: ConfirmService,
38 protected screenService: ScreenService,
39 private i18n: I18n,
40 private accountService: AccountService,
41 private videoService: VideoService
42 ) {
43 super()
44
45 this.titlePage = this.i18n('Published videos')
46 }
47
48 ngOnInit () {
49 super.ngOnInit()
50
51 // Parent get the account for us
52 this.accountSub = this.accountService.accountLoaded
53 .subscribe(account => {
54 this.account = account
55
56 this.reloadVideos()
57 this.generateSyndicationList()
58 })
59 }
60
61 ngOnDestroy () {
62 if (this.accountSub) this.accountSub.unsubscribe()
63
64 super.ngOnDestroy()
65 }
66
67 getVideosObservable (page: number) {
68 const newPagination = immutableAssign(this.pagination, { currentPage: page })
69
70 return this.videoService
71 .getAccountVideos(this.account, newPagination, this.sort)
72 .pipe(
73 tap(({ totalVideos }) => {
74 this.titlePage = this.i18n('Published {{totalVideos}} videos', { totalVideos })
75 })
76 )
77 }
78
79 generateSyndicationList () {
80 this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id)
81 }
82 }