1 import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { AuthService, LocalStorageService, Notifier, ScreenService, ServerService, UserService } from '@app/core'
4 import { HooksService } from '@app/core/plugins/hooks.service'
5 import { immutableAssign } from '@app/helpers'
6 import { VideoService } from '@app/shared/shared-main'
7 import { AbstractVideoList } from '@app/shared/shared-video-miniature'
8 import { VideoSortField } from '@shared/models'
9 import { VideoTrendingHeaderComponent } from './video-trending-header.component'
12 selector: 'my-videos-trending',
13 styleUrls: [ '../../../shared/shared-video-miniature/abstract-video-list.scss' ],
14 templateUrl: '../../../shared/shared-video-miniature/abstract-video-list.html'
16 export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
17 HeaderComponent = VideoTrendingHeaderComponent
19 defaultSort: VideoSortField = '-trending'
21 useUserVideoPreferences = true
24 protected router: Router,
25 protected serverService: ServerService,
26 protected route: ActivatedRoute,
27 protected notifier: Notifier,
28 protected authService: AuthService,
29 protected userService: UserService,
30 protected screenService: ScreenService,
31 protected storageService: LocalStorageService,
32 protected cfr: ComponentFactoryResolver,
33 private videoService: VideoService,
34 private hooks: HooksService
38 this.headerComponentInjector = this.getInjector()
44 this.generateSyndicationList()
46 this.serverService.getConfig().subscribe(
48 const trendingDays = config.trending.videos.intervalDays
50 if (trendingDays === 1) {
51 this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last 24 hours`
53 this.titleTooltip = $localize`Trending videos are those totalizing the greatest number of views during the last ${trendingDays} days`
56 this.headerComponentInjector = this.getInjector()
65 getVideosObservable (page: number) {
66 const newPagination = immutableAssign(this.pagination, { currentPage: page })
68 videoPagination: newPagination,
70 categoryOneOf: this.categoryOneOf,
71 languageOneOf: this.languageOneOf,
72 nsfwPolicy: this.nsfwPolicy,
76 return this.hooks.wrapObsFun(
77 this.videoService.getVideos.bind(this.videoService),
80 'filter:api.trending-videos.videos.list.params',
81 'filter:api.trending-videos.videos.list.result'
85 generateSyndicationList () {
86 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
90 return Injector.create({
94 model: this.defaultSort