]>
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 | ||
10 | @Component({ | |
11 | selector: 'my-account-videos', | |
12 | templateUrl: '../../shared/shared-video-miniature/abstract-video-list.html', | |
13 | styleUrls: [ | |
14 | '../../shared/shared-video-miniature/abstract-video-list.scss' | |
15 | ] | |
16 | }) | |
17 | export class AccountVideosComponent extends AbstractVideoList implements OnInit, OnDestroy { | |
18 | titlePage: string | |
19 | loadOnInit = false | |
20 | ||
21 | private account: Account | |
22 | private accountSub: Subscription | |
23 | ||
24 | constructor ( | |
25 | protected router: Router, | |
26 | protected serverService: ServerService, | |
27 | protected route: ActivatedRoute, | |
28 | protected authService: AuthService, | |
29 | protected userService: UserService, | |
30 | protected notifier: Notifier, | |
31 | protected confirmService: ConfirmService, | |
32 | protected screenService: ScreenService, | |
33 | protected storageService: LocalStorageService, | |
34 | private accountService: AccountService, | |
35 | private videoService: VideoService | |
36 | ) { | |
37 | super() | |
38 | } | |
39 | ||
40 | ngOnInit () { | |
41 | super.ngOnInit() | |
42 | ||
43 | // Parent get the account for us | |
44 | this.accountSub = this.accountService.accountLoaded | |
45 | .pipe(first()) | |
46 | .subscribe(account => { | |
47 | this.account = account | |
48 | ||
49 | this.reloadVideos() | |
50 | this.generateSyndicationList() | |
51 | }) | |
52 | } | |
53 | ||
54 | ngOnDestroy () { | |
55 | if (this.accountSub) this.accountSub.unsubscribe() | |
56 | ||
57 | super.ngOnDestroy() | |
58 | } | |
59 | ||
60 | getVideosObservable (page: number) { | |
61 | const newPagination = immutableAssign(this.pagination, { currentPage: page }) | |
62 | ||
63 | return this.videoService | |
64 | .getAccountVideos(this.account, newPagination, this.sort) | |
65 | .pipe( | |
66 | tap(({ total }) => { | |
67 | this.titlePage = $localize`Published ${total} videos` | |
68 | }) | |
69 | ) | |
70 | } | |
71 | ||
72 | generateSyndicationList () { | |
73 | this.syndicationItems = this.videoService.getAccountFeedUrls(this.account.id) | |
74 | } | |
75 | } |