]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/videos/video-list/video-trending.component.ts
Lazy load static objects
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-list / video-trending.component.ts
... / ...
CommitLineData
1import { Component, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
3import { immutableAssign } from '@app/shared/misc/utils'
4import { AuthService } from '../../core/auth'
5import { AbstractVideoList } from '../../shared/video/abstract-video-list'
6import { VideoSortField } from '../../shared/video/sort-field.type'
7import { VideoService } from '../../shared/video/video.service'
8import { I18n } from '@ngx-translate/i18n-polyfill'
9import { ScreenService } from '@app/shared/misc/screen.service'
10import { Notifier, ServerService } from '@app/core'
11import { HooksService } from '@app/core/plugins/hooks.service'
12
13@Component({
14 selector: 'my-videos-trending',
15 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
16 templateUrl: '../../shared/video/abstract-video-list.html'
17})
18export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
19 titlePage: string
20 defaultSort: VideoSortField = '-trending'
21
22 useUserVideoLanguagePreferences = true
23
24 constructor (
25 protected i18n: I18n,
26 protected router: Router,
27 protected serverService: ServerService,
28 protected route: ActivatedRoute,
29 protected notifier: Notifier,
30 protected authService: AuthService,
31 protected screenService: ScreenService,
32 private videoService: VideoService,
33 private hooks: HooksService
34 ) {
35 super()
36 }
37
38 ngOnInit () {
39 super.ngOnInit()
40
41 this.generateSyndicationList()
42
43 this.serverService.getConfig().subscribe(
44 config => {
45 const trendingDays = config.trending.videos.intervalDays
46
47 if (trendingDays === 1) {
48 this.titlePage = this.i18n('Trending for the last 24 hours')
49 this.titleTooltip = this.i18n('Trending videos are those totalizing the greatest number of views during the last 24 hours')
50 } else {
51 this.titlePage = this.i18n('Trending for the last {{days}} days', { days: trendingDays })
52 this.titleTooltip = this.i18n(
53 'Trending videos are those totalizing the greatest number of views during the last {{days}} days',
54 { days: trendingDays }
55 )
56 }
57 })
58 }
59
60 ngOnDestroy () {
61 super.ngOnDestroy()
62 }
63
64 getVideosObservable (page: number) {
65 const newPagination = immutableAssign(this.pagination, { currentPage: page })
66 const params = {
67 videoPagination: newPagination,
68 sort: this.sort,
69 categoryOneOf: this.categoryOneOf,
70 languageOneOf: this.languageOneOf
71 }
72
73 return this.hooks.wrapObsFun(
74 this.videoService.getVideos.bind(this.videoService),
75 params,
76 'common',
77 'filter:api.trending-videos.videos.list.params',
78 'filter:api.trending-videos.videos.list.result'
79 )
80 }
81
82 generateSyndicationList () {
83 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
84 }
85}