]>
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 { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' | |
6 | import { MiniatureDisplayOptions, VideoFilters } from '@app/shared/shared-video-miniature' | |
7 | import { VideoSortField } from '@shared/models/videos' | |
8 | ||
9 | @Component({ | |
10 | selector: 'my-video-channel-videos', | |
11 | templateUrl: './video-channel-videos.component.html' | |
12 | }) | |
13 | export class VideoChannelVideosComponent 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 | displayOptions: MiniatureDisplayOptions = { | |
21 | date: true, | |
22 | views: true, | |
23 | by: false, | |
24 | avatar: false, | |
25 | privacyLabel: true, | |
26 | privacyText: false, | |
27 | state: false, | |
28 | blacklistInfo: false | |
29 | } | |
30 | ||
31 | videoChannel: VideoChannel | |
32 | disabled = false | |
33 | ||
34 | private videoChannelSub: Subscription | |
35 | ||
36 | constructor ( | |
37 | private screenService: ScreenService, | |
38 | private videoChannelService: VideoChannelService, | |
39 | private videoService: VideoService | |
40 | ) { | |
41 | } | |
42 | ||
43 | ngOnInit () { | |
44 | // Parent get the video channel for us | |
45 | this.videoChannelService.videoChannelLoaded.pipe(first()) | |
46 | .subscribe(videoChannel => { | |
47 | this.videoChannel = videoChannel | |
48 | }) | |
49 | } | |
50 | ||
51 | ngOnDestroy () { | |
52 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() | |
53 | } | |
54 | ||
55 | getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) { | |
56 | const params = { | |
57 | ...filters.toVideosAPIObject(), | |
58 | ||
59 | videoPagination: pagination, | |
60 | videoChannel: this.videoChannel, | |
61 | skipCount: true | |
62 | } | |
63 | ||
64 | return this.videoService.getVideoChannelVideos(params) | |
65 | } | |
66 | ||
67 | getSyndicationItems () { | |
68 | return this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) | |
69 | } | |
70 | ||
71 | displayAsRow () { | |
72 | return this.screenService.isInMobileView() | |
73 | } | |
74 | ||
75 | disableForReuse () { | |
76 | this.disabled = true | |
77 | } | |
78 | ||
79 | enabledForReuse () { | |
80 | this.disabled = false | |
81 | } | |
82 | } |