1 import { Component, HostBinding, Inject, OnDestroy, OnInit } from '@angular/core'
2 import { ActivatedRoute, Router } from '@angular/router'
3 import { VideoListHeaderComponent } from '@app/shared/shared-video-miniature'
4 import { GlobalIconName } from '@app/shared/shared-icons'
5 import { ServerService } from '@app/core/server/server.service'
6 import { Subscription } from 'rxjs'
7 import { AuthService, RedirectService } from '@app/core'
9 interface VideoTrendingHeaderItem {
11 iconName: GlobalIconName
18 selector: 'video-trending-title-page',
19 styleUrls: [ './video-trending-header.component.scss' ],
20 templateUrl: './video-trending-header.component.html'
22 export class VideoTrendingHeaderComponent extends VideoListHeaderComponent implements OnInit, OnDestroy {
23 @HostBinding('class') class = 'title-page title-page-single'
25 buttons: VideoTrendingHeaderItem[]
27 private algorithmChangeSub: Subscription
30 @Inject('data') public data: any,
31 private route: ActivatedRoute,
32 private router: Router,
33 private auth: AuthService,
34 private serverService: ServerService
40 label: $localize`:A variant of Trending videos based on the number of recent interactions, minus user history:Best`,
43 tooltip: $localize`Videos with the most interactions for recent videos, minus user history`,
47 label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`,
50 tooltip: $localize`Videos with the most interactions for recent videos`,
54 label: $localize`:Main variant of Trending videos based on number of recent views:Views`,
57 tooltip: $localize`Videos with the most views during the last 24 hours`
60 label: $localize`:A variant of Trending videos based on the number of likes:Likes`,
63 tooltip: $localize`Videos that have the most likes`
69 this.serverService.getConfig()
70 .subscribe(config => {
71 const algEnabled = config.trending.videos.algorithms.enabled
73 this.buttons = this.buttons.map(b => {
74 b.hidden = !algEnabled.includes(b.value)
76 // Best is adapted by the user history so
77 if (b.value === 'best' && !this.auth.isLoggedIn()) {
85 this.algorithmChangeSub = this.route.queryParams.subscribe(
87 const algorithm = queryParams['alg']
89 this.data.model = algorithm
91 this.data.model = RedirectService.DEFAULT_TRENDING_ALGORITHM
98 if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe()
102 const alg = this.data.model !== RedirectService.DEFAULT_TRENDING_ALGORITHM
106 this.router.navigate(
109 relativeTo: this.route,
110 queryParams: { alg },
111 queryParamsHandling: 'merge'