]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+videos/video-list/trending/video-trending-header.component.ts
Use HTML config when possible
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / video-list / trending / video-trending-header.component.ts
index a4a1e358f5fd17c44b7625605bf1b117a422346b..6c2b32a4fb92dbbabb60304022bd35facb088cca 100644 (file)
@@ -1,10 +1,10 @@
+import { Subscription } from 'rxjs'
 import { Component, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
-import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature'
-import { GlobalIconName } from '@app/shared/shared-icons'
+import { AuthService, RedirectService } from '@app/core'
 import { ServerService } from '@app/core/server/server.service'
-import { Subscription } from 'rxjs'
-import { RedirectService } from '@app/core'
+import { GlobalIconName } from '@app/shared/shared-icons'
+import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature'
 
 interface VideoTrendingHeaderItem {
   label: string
@@ -30,7 +30,9 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent imple
     @Inject('data') public data: any,
     private route: ActivatedRoute,
     private router: Router,
-    private serverService: ServerService
+    private auth: AuthService,
+    private serverService: ServerService,
+    private redirectService: RedirectService
   ) {
     super(data)
 
@@ -39,21 +41,21 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent imple
         label: $localize`:A variant of Trending videos based on the number of recent interactions, minus user history:Best`,
         iconName: 'award',
         value: 'best',
-        tooltip: $localize`Videos totalizing the most interactions for recent videos, minus user history`,
+        tooltip: $localize`Videos with the most interactions for recent videos, minus user history`,
         hidden: true
       },
       {
         label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`,
         iconName: 'flame',
         value: 'hot',
-        tooltip: $localize`Videos totalizing the most interactions for recent videos`,
+        tooltip: $localize`Videos with the most interactions for recent videos`,
         hidden: true
       },
       {
         label: $localize`:Main variant of Trending videos based on number of recent views:Views`,
         iconName: 'trending',
         value: 'most-viewed',
-        tooltip: $localize`Videos totalizing the most views during the last 24 hours`
+        tooltip: $localize`Videos with the most views during the last 24 hours`
       },
       {
         label: $localize`:A variant of Trending videos based on the number of likes:Likes`,
@@ -65,22 +67,23 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent imple
   }
 
   ngOnInit () {
-    this.serverService.getConfig()
-        .subscribe(config => {
-          this.buttons = this.buttons.map(b => {
-            b.hidden = !config.trending.videos.algorithms.enabled.includes(b.value)
-            return b
-          })
-        })
+    const serverConfig = this.serverService.getHTMLConfig()
+    const algEnabled = serverConfig.trending.videos.algorithms.enabled
+
+    this.buttons = this.buttons.map(b => {
+      b.hidden = !algEnabled.includes(b.value)
+
+      // Best is adapted by the user history so
+      if (b.value === 'best' && !this.auth.isLoggedIn()) {
+        b.hidden = true
+      }
+
+      return b
+    })
 
     this.algorithmChangeSub = this.route.queryParams.subscribe(
       queryParams => {
-        const algorithm = queryParams['alg']
-        if (algorithm) {
-          this.data.model = algorithm
-        } else {
-          this.data.model = RedirectService.DEFAULT_TRENDING_ALGORITHM
-        }
+        this.data.model = queryParams['alg'] || this.redirectService.getDefaultTrendingAlgorithm()
       }
     )
   }
@@ -90,7 +93,7 @@ export class VideoTrendingHeaderComponent extends VideoListHeaderComponent imple
   }
 
   setSort () {
-    const alg = this.data.model !== RedirectService.DEFAULT_TRENDING_ALGORITHM
+    const alg = this.data.model !== this.redirectService.getDefaultTrendingAlgorithm()
       ? this.data.model
       : undefined