]>
Commit | Line | Data |
---|---|---|
dd24f1bb | 1 | import { Subscription } from 'rxjs' |
9df52d66 | 2 | import { first } from 'rxjs/operators' |
9ca0f688 C |
3 | import { AfterViewInit, Component, OnDestroy, OnInit } from '@angular/core' |
4 | import { ComponentPaginationLight, DisableForReuseHook, HooksService, ScreenService } from '@app/core' | |
67ed6552 | 5 | import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' |
dd24f1bb | 6 | import { MiniatureDisplayOptions, VideoFilters } from '@app/shared/shared-video-miniature' |
9ca0f688 | 7 | import { Video, VideoSortField } from '@shared/models' |
0626e7af C |
8 | |
9 | @Component({ | |
170726f5 | 10 | selector: 'my-video-channel-videos', |
dd24f1bb | 11 | templateUrl: './video-channel-videos.component.html' |
0626e7af | 12 | }) |
9ca0f688 | 13 | export class VideoChannelVideosComponent implements OnInit, AfterViewInit, OnDestroy, DisableForReuseHook { |
dd24f1bb C |
14 | getVideosObservableFunction = this.getVideosObservable.bind(this) |
15 | getSyndicationItemsFunction = this.getSyndicationItems.bind(this) | |
0626e7af | 16 | |
dd24f1bb C |
17 | title = $localize`Videos` |
18 | defaultSort = '-publishedAt' as VideoSortField | |
0aa52e17 | 19 | |
900f7820 C |
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 | ||
dd24f1bb C |
31 | videoChannel: VideoChannel |
32 | disabled = false | |
33 | ||
734a5ceb | 34 | private videoChannelSub: Subscription |
0626e7af C |
35 | |
36 | constructor ( | |
dd24f1bb | 37 | private screenService: ScreenService, |
170726f5 | 38 | private videoChannelService: VideoChannelService, |
9ca0f688 C |
39 | private videoService: VideoService, |
40 | private hooks: HooksService | |
0626e7af | 41 | ) { |
0626e7af C |
42 | } |
43 | ||
44 | ngOnInit () { | |
170726f5 | 45 | // Parent get the video channel for us |
dd24f1bb C |
46 | this.videoChannelService.videoChannelLoaded.pipe(first()) |
47 | .subscribe(videoChannel => { | |
48 | this.videoChannel = videoChannel | |
9ca0f688 C |
49 | |
50 | this.hooks.runAction('action:video-channel-videos.video-channel.loaded', 'video-channel', { videoChannel }) | |
dd24f1bb | 51 | }) |
0626e7af C |
52 | } |
53 | ||
9ca0f688 C |
54 | ngAfterViewInit () { |
55 | this.hooks.runAction('action:video-channel-videos.init', 'video-channel') | |
56 | } | |
57 | ||
0626e7af | 58 | ngOnDestroy () { |
734a5ceb | 59 | if (this.videoChannelSub) this.videoChannelSub.unsubscribe() |
0626e7af C |
60 | } |
61 | ||
dd24f1bb C |
62 | getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) { |
63 | const params = { | |
64 | ...filters.toVideosAPIObject(), | |
65 | ||
66 | videoPagination: pagination, | |
0aa52e17 | 67 | videoChannel: this.videoChannel, |
dd24f1bb | 68 | skipCount: true |
0aa52e17 | 69 | } |
0626e7af | 70 | |
dd24f1bb | 71 | return this.videoService.getVideoChannelVideos(params) |
0626e7af C |
72 | } |
73 | ||
dd24f1bb C |
74 | getSyndicationItems () { |
75 | return this.videoService.getVideoChannelFeedUrls(this.videoChannel.id) | |
0626e7af | 76 | } |
0aa52e17 | 77 | |
dd24f1bb C |
78 | displayAsRow () { |
79 | return this.screenService.isInMobileView() | |
80 | } | |
0aa52e17 | 81 | |
dd24f1bb C |
82 | disableForReuse () { |
83 | this.disabled = true | |
0aa52e17 | 84 | } |
4d5e572f | 85 | |
dd24f1bb C |
86 | enabledForReuse () { |
87 | this.disabled = false | |
4d5e572f | 88 | } |
9ca0f688 C |
89 | |
90 | onVideosLoaded (videos: Video[]) { | |
91 | this.hooks.runAction('action:video-channel-videos.videos.loaded', 'video-channel', { videos }) | |
92 | } | |
0626e7af | 93 | } |