]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/videos/video-list/video-trending.component.ts
Handle overview pagination in client
[github/Chocobozzz/PeerTube.git] / client / src / app / videos / video-list / video-trending.component.ts
CommitLineData
9af61e84 1import { Component, OnDestroy, OnInit } from '@angular/core'
9bf9d2a5 2import { ActivatedRoute, Router } from '@angular/router'
0cd4344f 3import { immutableAssign } from '@app/shared/misc/utils'
b2731bff 4import { AuthService } from '../../core/auth'
7bfd1b1e 5import { AbstractVideoList } from '../../shared/video/abstract-video-list'
7b87d2d5 6import { VideoSortField } from '../../shared/video/sort-field.type'
f3aaa9a9 7import { VideoService } from '../../shared/video/video.service'
989e526a 8import { I18n } from '@ngx-translate/i18n-polyfill'
bbe0f064 9import { ScreenService } from '@app/shared/misc/screen.service'
9b4b15f9 10import { Notifier, ServerService } from '@app/core'
93cae479 11import { HooksService } from '@app/core/plugins/hooks.service'
d3217560
RK
12import { UserService } from '@app/shared'
13import { LocalStorageService } from '@app/shared/misc/storage.service'
9bf9d2a5
C
14
15@Component({
16 selector: 'my-videos-trending',
202f6b6c
C
17 styleUrls: [ '../../shared/video/abstract-video-list.scss' ],
18 templateUrl: '../../shared/video/abstract-video-list.html'
9bf9d2a5 19})
9af61e84 20export class VideoTrendingComponent extends AbstractVideoList implements OnInit, OnDestroy {
989e526a 21 titlePage: string
9a629c6e 22 defaultSort: VideoSortField = '-trending'
9bf9d2a5 23
3caf77d3
C
24 useUserVideoLanguagePreferences = true
25
989e526a 26 constructor (
34c7f429 27 protected i18n: I18n,
989e526a 28 protected router: Router,
489290b8 29 protected serverService: ServerService,
989e526a 30 protected route: ActivatedRoute,
f8b2c1b4 31 protected notifier: Notifier,
989e526a 32 protected authService: AuthService,
d3217560 33 protected userService: UserService,
bbe0f064 34 protected screenService: ScreenService,
d3217560 35 protected storageService: LocalStorageService,
93cae479
C
36 private videoService: VideoService,
37 private hooks: HooksService
989e526a 38 ) {
9bf9d2a5
C
39 super()
40 }
41
42 ngOnInit () {
43 super.ngOnInit()
cc1561f9 44
244e76a5 45 this.generateSyndicationList()
7b95f313 46
ba430d75
C
47 this.serverService.getConfig().subscribe(
48 config => {
49 const trendingDays = config.trending.videos.intervalDays
7b95f313 50
572b8e02
C
51 if (trendingDays === 1) {
52 this.titlePage = this.i18n('Trending for the last 24 hours')
1aabcae7 53 this.titleTooltip = this.i18n('Trending videos are those totalizing the greatest number of views during the last 24 hours')
572b8e02
C
54 } else {
55 this.titlePage = this.i18n('Trending for the last {{days}} days', { days: trendingDays })
56 this.titleTooltip = this.i18n(
1aabcae7 57 'Trending videos are those totalizing the greatest number of views during the last {{days}} days',
572b8e02
C
58 { days: trendingDays }
59 )
60 }
61 })
9bf9d2a5
C
62 }
63
9af61e84
C
64 ngOnDestroy () {
65 super.ngOnDestroy()
66 }
67
0cd4344f
C
68 getVideosObservable (page: number) {
69 const newPagination = immutableAssign(this.pagination, { currentPage: page })
93cae479 70 const params = {
3caf77d3
C
71 videoPagination: newPagination,
72 sort: this.sort,
3caf77d3 73 categoryOneOf: this.categoryOneOf,
440d39c5
C
74 languageOneOf: this.languageOneOf,
75 skipCount: true
93cae479
C
76 }
77
78 return this.hooks.wrapObsFun(
79 this.videoService.getVideos.bind(this.videoService),
80 params,
81 'common',
7663e55a
C
82 'filter:api.trending-videos.videos.list.params',
83 'filter:api.trending-videos.videos.list.result'
93cae479 84 )
9bf9d2a5 85 }
244e76a5
RK
86
87 generateSyndicationList () {
d59cba29 88 this.syndicationItems = this.videoService.getVideoFeedUrls(this.sort, undefined, this.categoryOneOf)
244e76a5 89 }
9bf9d2a5 90}