diff options
Diffstat (limited to 'client/src/app/+videos')
-rw-r--r-- | client/src/app/+videos/video-list/trending/video-trending.component.ts | 27 |
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 @@ | |||
1 | import { Subscription } from 'rxjs' | ||
2 | import { first, switchMap } from 'rxjs/operators' | ||
1 | import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core' | 3 | import { Component, ComponentFactoryResolver, Injector, OnDestroy, OnInit } from '@angular/core' |
2 | import { ActivatedRoute, Router } from '@angular/router' | 4 | import { ActivatedRoute, Params, Router } from '@angular/router' |
3 | import { AuthService, LocalStorageService, Notifier, RedirectService, ScreenService, ServerService, UserService } from '@app/core' | 5 | import { AuthService, LocalStorageService, Notifier, RedirectService, ScreenService, ServerService, UserService } from '@app/core' |
4 | import { HooksService } from '@app/core/plugins/hooks.service' | 6 | import { HooksService } from '@app/core/plugins/hooks.service' |
5 | import { immutableAssign } from '@app/helpers' | 7 | import { immutableAssign } from '@app/helpers' |
6 | import { VideoService } from '@app/shared/shared-main' | 8 | import { VideoService } from '@app/shared/shared-main' |
7 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' | 9 | import { AbstractVideoList } from '@app/shared/shared-video-miniature' |
8 | import { VideoSortField } from '@shared/models' | 10 | import { VideoSortField } from '@shared/models' |
9 | import { Subscription } from 'rxjs' | ||
10 | import { VideoTrendingHeaderComponent } from './video-trending-header.component' | 11 | import { 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': |