diff options
author | Chocobozzz <me@florianbigard.com> | 2021-02-22 09:46:28 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-02-22 10:35:37 +0100 |
commit | 15bedeebd7671bf5177879899404d48942b2d090 (patch) | |
tree | 6313b11956ea44dd80f409fb2d48f62b11765c13 | |
parent | 94d721efdc9a8c2cda612f49506a41adb6a06f1d (diff) | |
download | PeerTube-15bedeebd7671bf5177879899404d48942b2d090.tar.gz PeerTube-15bedeebd7671bf5177879899404d48942b2d090.tar.zst PeerTube-15bedeebd7671bf5177879899404d48942b2d090.zip |
Fix loading things twice on trending page
3 files changed, 35 insertions, 12 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': |
diff --git a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts index f8abc1656..c13cb3748 100644 --- a/client/src/app/shared/shared-video-miniature/abstract-video-list.ts +++ b/client/src/app/shared/shared-video-miniature/abstract-video-list.ts | |||
@@ -11,7 +11,7 @@ import { | |||
11 | ViewChild, | 11 | ViewChild, |
12 | ViewContainerRef | 12 | ViewContainerRef |
13 | } from '@angular/core' | 13 | } from '@angular/core' |
14 | import { ActivatedRoute, Router } from '@angular/router' | 14 | import { ActivatedRoute, Params, Router } from '@angular/router' |
15 | import { | 15 | import { |
16 | AuthService, | 16 | AuthService, |
17 | ComponentPaginationLight, | 17 | ComponentPaginationLight, |
@@ -199,6 +199,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterConte | |||
199 | // No more results | 199 | // No more results |
200 | if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return | 200 | if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return |
201 | 201 | ||
202 | console.log('near of bottom') | ||
202 | this.pagination.currentPage += 1 | 203 | this.pagination.currentPage += 1 |
203 | 204 | ||
204 | this.setScrollRouteParams() | 205 | this.setScrollRouteParams() |
@@ -322,10 +323,17 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, AfterConte | |||
322 | // On videos hook for children that want to do something | 323 | // On videos hook for children that want to do something |
323 | protected onMoreVideos () { /* empty */ } | 324 | protected onMoreVideos () { /* empty */ } |
324 | 325 | ||
325 | protected loadRouteParams (routeParams: { [ key: string ]: any }) { | 326 | protected load () { /* empty */ } |
326 | this.sort = routeParams[ 'sort' ] as VideoSortField || this.defaultSort | 327 | |
327 | this.categoryOneOf = routeParams[ 'categoryOneOf' ] | 328 | // Hook if the page has custom route params |
328 | this.angularState = routeParams[ 'a-state' ] | 329 | protected loadPageRouteParams (_queryParams: Params) { /* empty */ } |
330 | |||
331 | protected loadRouteParams (queryParams: Params) { | ||
332 | this.sort = queryParams[ 'sort' ] as VideoSortField || this.defaultSort | ||
333 | this.categoryOneOf = queryParams[ 'categoryOneOf' ] | ||
334 | this.angularState = queryParams[ 'a-state' ] | ||
335 | |||
336 | this.loadPageRouteParams(queryParams) | ||
329 | } | 337 | } |
330 | 338 | ||
331 | protected buildLocalFilter (existing: VideoFilter, base: VideoFilter) { | 339 | protected buildLocalFilter (existing: VideoFilter, base: VideoFilter) { |
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts index cff19223f..4c00d97f8 100644 --- a/server/tests/api/notifications/moderation-notifications.ts +++ b/server/tests/api/notifications/moderation-notifications.ts | |||
@@ -121,6 +121,8 @@ describe('Test moderation notifications', function () { | |||
121 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + uuidv4()) | 121 | const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + uuidv4()) |
122 | const comment = resComment.body.comment | 122 | const comment = resComment.body.comment |
123 | 123 | ||
124 | await waitJobs(servers) | ||
125 | |||
124 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) | 126 | await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) |
125 | 127 | ||
126 | await waitJobs(servers) | 128 | await waitJobs(servers) |