]>
Commit | Line | Data |
---|---|---|
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 { I18n } from '@ngx-translate/i18n-polyfill' | |
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 | './account-videos.component.scss' | |
17 | ] | |
18 | }) | |
19 | export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
20 | titlePage: string | |
21 | loadOnInit = false | |
22 | ||
23 | private account: Account | |
24 | private accountSub: Subscription | |
25 | ||
26 | constructor ( | |
27 | protected i18n: I18n, | |
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 | // Parent get the account for us | |
47 | this.accountSub = this.accountService.accountLoaded | |
48 | .pipe(first()) | |
49 | .subscribe(account => { | |
50 | this.account = account | |
51 | ||
52 | this.reloadVideos() | |
53 | this.generateSyndicationList() | |
54 | }) | |
55 | } | |
56 | ||
57 | ngOnDestroy () { | |
58 | if (this.accountSub) this.accountSub.unsubscribe() | |
59 | ||
60 | super.ngOnDestroy() | |
61 | } | |
62 | ||
63 | getVideosObservable (page: number) { | |
64 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
65 | ||
66 | return this.videoService | |
67 | .getAccountVideos(this.account, newPagination, this.sort) | |
68 | .pipe( | |
69 | tap(({ total }) => { | |
70 | this.titlePage = this.i18n('Published {{total}} videos', { total }) | |
71 | }) | |
72 | ) | |
73 | } | |
74 | ||
75 | generateSyndicationList () { | |
76 | this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id) | |
77 | } | |
78 | } |