]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/video-list/trending/video-trending-header.component.ts
Load server config on app init
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / video-list / trending / video-trending-header.component.ts
CommitLineData
ba5d4a84
RK
1import { Component, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router'
5bcbcbe3
RK
3import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature'
4import { GlobalIconName } from '@app/shared/shared-icons'
3da68f0a 5import { ServerService } from '@app/core/server/server.service'
ba5d4a84 6import { Subscription } from 'rxjs'
e6ea0cac 7import { AuthService, RedirectService } from '@app/core'
5bcbcbe3
RK
8
9interface VideoTrendingHeaderItem {
10 label: string
11 iconName: GlobalIconName
ba5d4a84 12 value: string
5bcbcbe3 13 tooltip?: string
3da68f0a 14 hidden?: boolean
5bcbcbe3
RK
15}
16
17@Component({
18 selector: 'video-trending-title-page',
5bcbcbe3
RK
19 styleUrls: [ './video-trending-header.component.scss' ],
20 templateUrl: './video-trending-header.component.html'
21})
ba5d4a84
RK
22export class VideoTrendingHeaderComponent extends VideoListHeaderComponent implements OnInit, OnDestroy {
23 @HostBinding('class') class = 'title-page title-page-single'
24
5bcbcbe3
RK
25 buttons: VideoTrendingHeaderItem[]
26
ba5d4a84
RK
27 private algorithmChangeSub: Subscription
28
5bcbcbe3
RK
29 constructor (
30 @Inject('data') public data: any,
ba5d4a84 31 private route: ActivatedRoute,
3da68f0a 32 private router: Router,
e6ea0cac 33 private auth: AuthService,
aea0b0e7
C
34 private serverService: ServerService,
35 private redirectService: RedirectService
5bcbcbe3
RK
36 ) {
37 super(data)
38
39 this.buttons = [
3d4e112d
RK
40 {
41 label: $localize`:A variant of Trending videos based on the number of recent interactions, minus user history:Best`,
42 iconName: 'award',
43 value: 'best',
8795d6f2 44 tooltip: $localize`Videos with the most interactions for recent videos, minus user history`,
3d4e112d
RK
45 hidden: true
46 },
5bcbcbe3
RK
47 {
48 label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`,
49 iconName: 'flame',
ba5d4a84 50 value: 'hot',
8795d6f2 51 tooltip: $localize`Videos with the most interactions for recent videos`,
3da68f0a 52 hidden: true
5bcbcbe3
RK
53 },
54 {
55 label: $localize`:Main variant of Trending videos based on number of recent views:Views`,
56 iconName: 'trending',
ba5d4a84 57 value: 'most-viewed',
8795d6f2 58 tooltip: $localize`Videos with the most views during the last 24 hours`
5bcbcbe3
RK
59 },
60 {
3da68f0a 61 label: $localize`:A variant of Trending videos based on the number of likes:Likes`,
5bcbcbe3 62 iconName: 'like',
ba5d4a84 63 value: 'most-liked',
5bcbcbe3
RK
64 tooltip: $localize`Videos that have the most likes`
65 }
66 ]
67 }
68
3da68f0a
RK
69 ngOnInit () {
70 this.serverService.getConfig()
71 .subscribe(config => {
e6ea0cac
C
72 const algEnabled = config.trending.videos.algorithms.enabled
73
ba5d4a84 74 this.buttons = this.buttons.map(b => {
e6ea0cac
C
75 b.hidden = !algEnabled.includes(b.value)
76
77 // Best is adapted by the user history so
78 if (b.value === 'best' && !this.auth.isLoggedIn()) {
79 b.hidden = true
80 }
81
ba5d4a84
RK
82 return b
83 })
3da68f0a 84 })
ba5d4a84
RK
85
86 this.algorithmChangeSub = this.route.queryParams.subscribe(
87 queryParams => {
aea0b0e7 88 this.data.model = queryParams['alg'] || this.redirectService.getDefaultTrendingAlgorithm()
ba5d4a84
RK
89 }
90 )
3da68f0a
RK
91 }
92
ba5d4a84
RK
93 ngOnDestroy () {
94 if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe()
3da68f0a
RK
95 }
96
5bcbcbe3 97 setSort () {
aea0b0e7 98 const alg = this.data.model !== this.redirectService.getDefaultTrendingAlgorithm()
ba5d4a84
RK
99 ? this.data.model
100 : undefined
101
102 this.router.navigate(
103 [],
104 {
105 relativeTo: this.route,
106 queryParams: { alg },
107 queryParamsHandling: 'merge'
108 }
109 )
5bcbcbe3
RK
110 }
111}