]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/video-list/trending/video-trending-header.component.ts
More robust channel change federation
[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
RK
6import { Subscription } from 'rxjs'
7import { 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
RK
32 private router: Router,
33 private serverService: ServerService
5bcbcbe3
RK
34 ) {
35 super(data)
36
37 this.buttons = [
3d4e112d
RK
38 {
39 label: $localize`:A variant of Trending videos based on the number of recent interactions, minus user history:Best`,
40 iconName: 'award',
41 value: 'best',
42 tooltip: $localize`Videos totalizing the most interactions for recent videos, minus user history`,
43 hidden: true
44 },
5bcbcbe3
RK
45 {
46 label: $localize`:A variant of Trending videos based on the number of recent interactions:Hot`,
47 iconName: 'flame',
ba5d4a84 48 value: 'hot',
5bcbcbe3 49 tooltip: $localize`Videos totalizing the most interactions for recent videos`,
3da68f0a 50 hidden: true
5bcbcbe3
RK
51 },
52 {
53 label: $localize`:Main variant of Trending videos based on number of recent views:Views`,
54 iconName: 'trending',
ba5d4a84
RK
55 value: 'most-viewed',
56 tooltip: $localize`Videos totalizing the most views during the last 24 hours`
5bcbcbe3
RK
57 },
58 {
3da68f0a 59 label: $localize`:A variant of Trending videos based on the number of likes:Likes`,
5bcbcbe3 60 iconName: 'like',
ba5d4a84 61 value: 'most-liked',
5bcbcbe3
RK
62 tooltip: $localize`Videos that have the most likes`
63 }
64 ]
65 }
66
3da68f0a
RK
67 ngOnInit () {
68 this.serverService.getConfig()
69 .subscribe(config => {
ba5d4a84
RK
70 this.buttons = this.buttons.map(b => {
71 b.hidden = !config.trending.videos.algorithms.enabled.includes(b.value)
72 return b
73 })
3da68f0a 74 })
ba5d4a84
RK
75
76 this.algorithmChangeSub = this.route.queryParams.subscribe(
77 queryParams => {
78 const algorithm = queryParams['alg']
79 if (algorithm) {
80 this.data.model = algorithm
81 } else {
82 this.data.model = RedirectService.DEFAULT_TRENDING_ALGORITHM
83 }
84 }
85 )
3da68f0a
RK
86 }
87
ba5d4a84
RK
88 ngOnDestroy () {
89 if (this.algorithmChangeSub) this.algorithmChangeSub.unsubscribe()
3da68f0a
RK
90 }
91
5bcbcbe3 92 setSort () {
ba5d4a84
RK
93 const alg = this.data.model !== RedirectService.DEFAULT_TRENDING_ALGORITHM
94 ? this.data.model
95 : undefined
96
97 this.router.navigate(
98 [],
99 {
100 relativeTo: this.route,
101 queryParams: { alg },
102 queryParamsHandling: 'merge'
103 }
104 )
5bcbcbe3
RK
105 }
106}