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 { 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 serverService: ServerService
39 label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`,
42 tooltip: $localize`Videos totalizing the most interactions for recent videos`,
46 label: $localize`:Main variant of Trending videos based on number of recent views:Views`,
49 tooltip: $localize`Videos totalizing the most views during the last 24 hours`
52 label: $localize`:A variant of Trending videos based on the number of likes:Likes`,
55 tooltip: $localize`Videos that have the most likes`
61 this.serverService.getConfig()
62 .subscribe(config => {
63 this.buttons = this.buttons.map(b => {
64 b.hidden = !config.trending.videos.algorithms.enabled.includes(b.value)
69 this.algorithmChangeSub = this.route.queryParams.subscribe(
71 const algorithm = queryParams['alg']
73 this.data.model = algorithm
75 this.data.model = RedirectService.DEFAULT_TRENDING_ALGORITHM
82 if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe()
86 const alg = this.data.model !== RedirectService.DEFAULT_TRENDING_ALGORITHM
93 relativeTo: this.route,
95 queryParamsHandling: 'merge'