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