1 import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { AuthService, LocalStorageService, Notifier, RedirectService, 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 { Subscription } from 'rxjs'
10 import { VideoTrendingHeaderComponent } from './video-trending-header.component'
13 selector: 'my-videos-hot',
14 styleUrls: [ '../../../shared/shared-video-miniature/abstract-video-list.scss' ],
15 templateUrl: '../../../shared/shared-video-miniature/abstract-video-list.html'
17 export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
18 HeaderComponent = VideoTrendingHeaderComponent
20 defaultSort: VideoSortField = '-trending'
22 useUserVideoPreferences = true
24 private algorithmChangeSub: Subscription
27 protected router: Router,
28 protected serverService: ServerService,
29 protected route: ActivatedRoute,
30 protected notifier: Notifier,
31 protected authService: AuthService,
32 protected userService: UserService,
33 protected screenService: ScreenService,
34 protected storageService: LocalStorageService,
35 protected cfr: ComponentFactoryResolver,
36 private videoService: VideoService,
37 private hooks: HooksService
41 this.defaultSort = this.parseAlgorithm(RedirectService.DEFAULT_TRENDING_ALGORITHM)
43 this.headerComponentInjector = this.getInjector()
49 this.generateSyndicationList()
51 this.algorithmChangeSub = this.route.queryParams.subscribe(
53 const algorithm = queryParams['alg'] || RedirectService.DEFAULT_TRENDING_ALGORITHM
55 this.sort = this.parseAlgorithm(algorithm)
63 if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe()
66 getVideosObservable (page: number) {
67 const newPagination = immutableAssign(this.pagination, { currentPage: page })
69 videoPagination: newPagination,
71 categoryOneOf: this.categoryOneOf,
72 languageOneOf: this.languageOneOf,
73 nsfwPolicy: this.nsfwPolicy,
77 return this.hooks.wrapObsFun(
78 this.videoService.getVideos.bind(this.videoService),
81 'filter:api.trending-videos.videos.list.params',
82 'filter:api.trending-videos.videos.list.result'
86 generateSyndicationList () {
87 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
91 return Injector.create({
95 model: this.defaultSort
101 private parseAlgorithm (algorithm: string): VideoSortField {
108 return '-' + algorithm as VideoSortField