aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/video-list
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-22 09:46:28 +0100
committerChocobozzz <me@florianbigard.com>2021-02-22 10:35:37 +0100
commit15bedeebd7671bf5177879899404d48942b2d090 (patch)
tree6313b11956ea44dd80f409fb2d48f62b11765c13 /client/src/app/+videos/video-list
parent94d721efdc9a8c2cda612f49506a41adb6a06f1d (diff)
downloadPeerTube-15bedeebd7671bf5177879899404d48942b2d090.tar.gz
PeerTube-15bedeebd7671bf5177879899404d48942b2d090.tar.zst
PeerTube-15bedeebd7671bf5177879899404d48942b2d090.zip
Fix loading things twice on trending page
Diffstat (limited to 'client/src/app/+videos/video-list')
-rw-r--r--client/src/app/+videos/video-list/trending/video-trending.component.ts27
1 files changed, 20 insertions, 7 deletions
diff --git a/client/src/app/+videos/video-list/trending/video-trending.component.ts b/client/src/app/+videos/video-list/trending/video-trending.component.ts
index c11f0da9d..e50d6ec3a 100644
--- a/client/src/app/+videos/video-list/trending/video-trending.component.ts
+++ b/client/src/app/+videos/video-list/trending/video-trending.component.ts
@@ -1,12 +1,13 @@
1import { Subscription } from 'rxjs'
2import { first, switchMap } from 'rxjs/operators'
1import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core' 3import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core'
2import { ActivatedRoute, Router } from '@angular/router' 4import { ActivatedRoute, Params, Router } from '@angular/router'
3import { AuthService, LocalStorageService, Notifier, RedirectService, ScreenService, ServerService, UserService } from '@app/core' 5import { AuthService, LocalStorageService, Notifier, RedirectService, ScreenService, ServerService, UserService } from '@app/core'
4import { HooksService } from '@app/core/plugins/hooks.service' 6import { HooksService } from '@app/core/plugins/hooks.service'
5import { immutableAssign } from '@app/helpers' 7import { immutableAssign } from '@app/helpers'
6import { VideoService } from '@app/shared/shared-main' 8import { VideoService } from '@app/shared/shared-main'
7import { AbstractVideoList } from '@app/shared/shared-video-miniature' 9import { AbstractVideoList } from '@app/shared/shared-video-miniature'
8import { VideoSortField } from '@shared/models' 10import { VideoSortField } from '@shared/models'
9import { Subscription } from 'rxjs'
10import { VideoTrendingHeaderComponent } from './video-trending-header.component' 11import { VideoTrendingHeaderComponent } from './video-trending-header.component'
11 12
12@Component({ 13@Component({
@@ -48,12 +49,18 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit,
48 49
49 this.generateSyndicationList() 50 this.generateSyndicationList()
50 51
51 this.algorithmChangeSub = this.route.queryParams.subscribe( 52 // Subscribe to alg change after we loaded the data
52 queryParams => { 53 // The initial alg load is handled by the parent class
53 const algorithm = queryParams['alg'] || RedirectService.DEFAULT_TRENDING_ALGORITHM 54 this.algorithmChangeSub = this.onDataSubject
55 .pipe(
56 first(),
57 switchMap(() => this.route.queryParams)
58 ).subscribe(queryParams => {
59 const oldSort = this.sort
60
61 this.loadPageRouteParams(queryParams)
54 62
55 this.sort = this.parseAlgorithm(algorithm) 63 if (oldSort !== this.sort) this.reloadVideos()
56 this.reloadVideos()
57 } 64 }
58 ) 65 )
59 } 66 }
@@ -98,6 +105,12 @@ export class VideoTrendingComponent extends AbstractVideoList implements OnInit,
98 }) 105 })
99 } 106 }
100 107
108 protected loadPageRouteParams (queryParams: Params) {
109 const algorithm = queryParams['alg'] || RedirectService.DEFAULT_TRENDING_ALGORITHM
110
111 this.sort = this.parseAlgorithm(algorithm)
112 }
113
101 private parseAlgorithm (algorithm: string): VideoSortField { 114 private parseAlgorithm (algorithm: string): VideoSortField {
102 switch (algorithm) { 115 switch (algorithm) {
103 case 'most-viewed': 116 case 'most-viewed':