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