]>
Commit | Line | Data |
---|---|---|
1 | import { Subscription } from 'rxjs' | |
2 | import { first } from 'rxjs/operators' | |
3 | import { Component, OnDestroy, OnInit } from '@angular/core' | |
4 | import { ComponentPaginationLight, DisableForReuseHook, ScreenService } from '@app/core' | |
5 | import { Account, AccountService, VideoService } from '@app/shared/shared-main' | |
6 | import { VideoFilters } from '@app/shared/shared-video-miniature' | |
7 | import { VideoSortField } from '@shared/models' | |
8 | ||
9 | @Component({ | |
10 | selector: 'my-account-videos', | |
11 | templateUrl: './account-videos.component.html' | |
12 | }) | |
13 | export class AccountVideosComponent implements OnInit, OnDestroy, DisableForReuseHook { | |
14 | getVideosObservableFunction = this.getVideosObservable.bind(this) | |
15 | getSyndicationItemsFunction = this.getSyndicationItems.bind(this) | |
16 | ||
17 | title = $localize`Videos` | |
18 | defaultSort = '-publishedAt' as VideoSortField | |
19 | ||
20 | account: Account | |
21 | disabled = false | |
22 | ||
23 | private accountSub: Subscription | |
24 | ||
25 | constructor ( | |
26 | private screenService: ScreenService, | |
27 | private accountService: AccountService, | |
28 | private videoService: VideoService | |
29 | ) { | |
30 | } | |
31 | ||
32 | ngOnInit () { | |
33 | // Parent get the account for us | |
34 | this.accountService.accountLoaded.pipe(first()) | |
35 | .subscribe(account => this.account = account) | |
36 | } | |
37 | ||
38 | ngOnDestroy () { | |
39 | if (this.accountSub) this.accountSub.unsubscribe() | |
40 | } | |
41 | ||
42 | getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) { | |
43 | const options = { | |
44 | ...filters.toVideosAPIObject(), | |
45 | ||
46 | videoPagination: pagination, | |
47 | account: this.account, | |
48 | skipCount: true | |
49 | } | |
50 | ||
51 | return this.videoService.getAccountVideos(options) | |
52 | } | |
53 | ||
54 | getSyndicationItems () { | |
55 | return this.videoService.getAccountFeedUrls(this.account.id) | |
56 | } | |
57 | ||
58 | displayAsRow () { | |
59 | return this.screenService.isInMobileView() | |
60 | } | |
61 | ||
62 | disableForReuse () { | |
63 | this.disabled = true | |
64 | } | |
65 | ||
66 | enabledForReuse () { | |
67 | this.disabled = false | |
68 | } | |
69 | } |