aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video/abstract-video-list.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-01-08 14:40:08 +0100
committerChocobozzz <me@florianbigard.com>2020-01-08 14:40:08 +0100
commit440d39c52d4efb878b6a2e21584d6b8f52072f27 (patch)
tree19ffd2dd545e125daf89c230e33d15f7827d10f7 /client/src/app/shared/video/abstract-video-list.ts
parentfe98765624cdd6695739bda719fcb726b71c2b2a (diff)
downloadPeerTube-440d39c52d4efb878b6a2e21584d6b8f52072f27.tar.gz
PeerTube-440d39c52d4efb878b6a2e21584d6b8f52072f27.tar.zst
PeerTube-440d39c52d4efb878b6a2e21584d6b8f52072f27.zip
Skip videos count on client if we don't use it
Diffstat (limited to 'client/src/app/shared/video/abstract-video-list.ts')
-rw-r--r--client/src/app/shared/video/abstract-video-list.ts24
1 files changed, 14 insertions, 10 deletions
diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts
index 06d4ed43d..c2fe6f754 100644
--- a/client/src/app/shared/video/abstract-video-list.ts
+++ b/client/src/app/shared/video/abstract-video-list.ts
@@ -3,7 +3,7 @@ import { OnDestroy, OnInit } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router' 3import { ActivatedRoute, Router } from '@angular/router'
4import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs' 4import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs'
5import { AuthService } from '../../core/auth' 5import { AuthService } from '../../core/auth'
6import { ComponentPagination } from '../rest/component-pagination.model' 6import { ComponentPaginationLight } from '../rest/component-pagination.model'
7import { VideoSortField } from './sort-field.type' 7import { VideoSortField } from './sort-field.type'
8import { Video } from './video.model' 8import { Video } from './video.model'
9import { ScreenService } from '@app/shared/misc/screen.service' 9import { ScreenService } from '@app/shared/misc/screen.service'
@@ -13,7 +13,7 @@ import { Notifier, ServerService } from '@app/core'
13import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' 13import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook'
14import { I18n } from '@ngx-translate/i18n-polyfill' 14import { I18n } from '@ngx-translate/i18n-polyfill'
15import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' 15import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date'
16import { ResultList, ServerConfig } from '@shared/models' 16import { ServerConfig } from '@shared/models'
17 17
18enum GroupDate { 18enum GroupDate {
19 UNKNOWN = 0, 19 UNKNOWN = 0,
@@ -25,10 +25,9 @@ enum GroupDate {
25} 25}
26 26
27export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableForReuseHook { 27export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableForReuseHook {
28 pagination: ComponentPagination = { 28 pagination: ComponentPaginationLight = {
29 currentPage: 1, 29 currentPage: 1,
30 itemsPerPage: 25, 30 itemsPerPage: 25
31 totalItems: null
32 } 31 }
33 sort: VideoSortField = '-publishedAt' 32 sort: VideoSortField = '-publishedAt'
34 33
@@ -47,6 +46,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
47 groupByDate = false 46 groupByDate = false
48 47
49 videos: Video[] = [] 48 videos: Video[] = []
49 hasDoneFirstQuery = false
50 disabled = false 50 disabled = false
51 51
52 displayOptions: MiniatureDisplayOptions = { 52 displayOptions: MiniatureDisplayOptions = {
@@ -84,7 +84,9 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
84 private groupedDateLabels: { [id in GroupDate]: string } 84 private groupedDateLabels: { [id in GroupDate]: string }
85 private groupedDates: { [id: number]: GroupDate } = {} 85 private groupedDates: { [id: number]: GroupDate } = {}
86 86
87 abstract getVideosObservable (page: number): Observable<ResultList<Video>> 87 private lastQueryLength: number
88
89 abstract getVideosObservable (page: number): Observable<{ data: Video[] }>
88 90
89 abstract generateSyndicationList (): void 91 abstract generateSyndicationList (): void
90 92
@@ -142,8 +144,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
142 onNearOfBottom () { 144 onNearOfBottom () {
143 if (this.disabled) return 145 if (this.disabled) return
144 146
145 // Last page 147 // No more results
146 if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return 148 if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return
147 149
148 this.pagination.currentPage += 1 150 this.pagination.currentPage += 1
149 151
@@ -154,8 +156,10 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor
154 156
155 loadMoreVideos (reset = false) { 157 loadMoreVideos (reset = false) {
156 this.getVideosObservable(this.pagination.currentPage).subscribe( 158 this.getVideosObservable(this.pagination.currentPage).subscribe(
157 ({ data, total }) => { 159 ({ data }) => {
158 this.pagination.totalItems = total 160 this.hasDoneFirstQuery = true
161 this.lastQueryLength = data.length
162
159 if (reset) this.videos = [] 163 if (reset) this.videos = []
160 this.videos = this.videos.concat(data) 164 this.videos = this.videos.concat(data)
161 165