aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/video')
-rw-r--r--client/src/app/shared/video/abstract-video-list.ts24
-rw-r--r--client/src/app/shared/video/video.service.ts36
2 files changed, 32 insertions, 28 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
diff --git a/client/src/app/shared/video/video.service.ts b/client/src/app/shared/video/video.service.ts
index 2dd47d74e..996202154 100644
--- a/client/src/app/shared/video/video.service.ts
+++ b/client/src/app/shared/video/video.service.ts
@@ -15,7 +15,7 @@ import {
15} from '../../../../../shared/models/videos' 15} from '../../../../../shared/models/videos'
16import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum' 16import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum'
17import { environment } from '../../../environments/environment' 17import { environment } from '../../../environments/environment'
18import { ComponentPagination } from '../rest/component-pagination.model' 18import { ComponentPaginationLight } from '../rest/component-pagination.model'
19import { RestExtractor } from '../rest/rest-extractor.service' 19import { RestExtractor } from '../rest/rest-extractor.service'
20import { RestService } from '../rest/rest.service' 20import { RestService } from '../rest/rest.service'
21import { UserService } from '../users/user.service' 21import { UserService } from '../users/user.service'
@@ -34,7 +34,7 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
34 34
35export interface VideosProvider { 35export interface VideosProvider {
36 getVideos (parameters: { 36 getVideos (parameters: {
37 videoPagination: ComponentPagination, 37 videoPagination: ComponentPaginationLight,
38 sort: VideoSortField, 38 sort: VideoSortField,
39 filter?: VideoFilter, 39 filter?: VideoFilter,
40 categoryOneOf?: number, 40 categoryOneOf?: number,
@@ -121,7 +121,7 @@ export class VideoService implements VideosProvider {
121 .pipe(catchError(err => this.restExtractor.handleError(err))) 121 .pipe(catchError(err => this.restExtractor.handleError(err)))
122 } 122 }
123 123
124 getMyVideos (videoPagination: ComponentPagination, sort: VideoSortField, search?: string): Observable<ResultList<Video>> { 124 getMyVideos (videoPagination: ComponentPaginationLight, sort: VideoSortField, search?: string): Observable<ResultList<Video>> {
125 const pagination = this.restService.componentPaginationToRestPagination(videoPagination) 125 const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
126 126
127 let params = new HttpParams() 127 let params = new HttpParams()
@@ -138,7 +138,7 @@ export class VideoService implements VideosProvider {
138 138
139 getAccountVideos ( 139 getAccountVideos (
140 account: Account, 140 account: Account,
141 videoPagination: ComponentPagination, 141 videoPagination: ComponentPaginationLight,
142 sort: VideoSortField 142 sort: VideoSortField
143 ): Observable<ResultList<Video>> { 143 ): Observable<ResultList<Video>> {
144 const pagination = this.restService.componentPaginationToRestPagination(videoPagination) 144 const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
@@ -156,7 +156,7 @@ export class VideoService implements VideosProvider {
156 156
157 getVideoChannelVideos ( 157 getVideoChannelVideos (
158 videoChannel: VideoChannel, 158 videoChannel: VideoChannel,
159 videoPagination: ComponentPagination, 159 videoPagination: ComponentPaginationLight,
160 sort: VideoSortField 160 sort: VideoSortField
161 ): Observable<ResultList<Video>> { 161 ): Observable<ResultList<Video>> {
162 const pagination = this.restService.componentPaginationToRestPagination(videoPagination) 162 const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
@@ -173,15 +173,18 @@ export class VideoService implements VideosProvider {
173 } 173 }
174 174
175 getUserSubscriptionVideos (parameters: { 175 getUserSubscriptionVideos (parameters: {
176 videoPagination: ComponentPagination, 176 videoPagination: ComponentPaginationLight,
177 sort: VideoSortField 177 sort: VideoSortField,
178 skipCount?: boolean
178 }): Observable<ResultList<Video>> { 179 }): Observable<ResultList<Video>> {
179 const { videoPagination, sort } = parameters 180 const { videoPagination, sort, skipCount } = parameters
180 const pagination = this.restService.componentPaginationToRestPagination(videoPagination) 181 const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
181 182
182 let params = new HttpParams() 183 let params = new HttpParams()
183 params = this.restService.addRestGetParams(params, pagination, sort) 184 params = this.restService.addRestGetParams(params, pagination, sort)
184 185
186 if (skipCount) params = params.set('skipCount', skipCount + '')
187
185 return this.authHttp 188 return this.authHttp
186 .get<ResultList<Video>>(UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/videos', { params }) 189 .get<ResultList<Video>>(UserSubscriptionService.BASE_USER_SUBSCRIPTIONS_URL + '/videos', { params })
187 .pipe( 190 .pipe(
@@ -191,26 +194,23 @@ export class VideoService implements VideosProvider {
191 } 194 }
192 195
193 getVideos (parameters: { 196 getVideos (parameters: {
194 videoPagination: ComponentPagination, 197 videoPagination: ComponentPaginationLight,
195 sort: VideoSortField, 198 sort: VideoSortField,
196 filter?: VideoFilter, 199 filter?: VideoFilter,
197 categoryOneOf?: number, 200 categoryOneOf?: number,
198 languageOneOf?: string[] 201 languageOneOf?: string[],
202 skipCount?: boolean
199 }): Observable<ResultList<Video>> { 203 }): Observable<ResultList<Video>> {
200 const { videoPagination, sort, filter, categoryOneOf, languageOneOf } = parameters 204 const { videoPagination, sort, filter, categoryOneOf, languageOneOf, skipCount } = parameters
201 205
202 const pagination = this.restService.componentPaginationToRestPagination(videoPagination) 206 const pagination = this.restService.componentPaginationToRestPagination(videoPagination)
203 207
204 let params = new HttpParams() 208 let params = new HttpParams()
205 params = this.restService.addRestGetParams(params, pagination, sort) 209 params = this.restService.addRestGetParams(params, pagination, sort)
206 210
207 if (filter) { 211 if (filter) params = params.set('filter', filter)
208 params = params.set('filter', filter) 212 if (categoryOneOf) params = params.set('categoryOneOf', categoryOneOf + '')
209 } 213 if (skipCount) params = params.set('skipCount', skipCount + '')
210
211 if (categoryOneOf) {
212 params = params.set('categoryOneOf', categoryOneOf + '')
213 }
214 214
215 if (languageOneOf) { 215 if (languageOneOf) {
216 for (const l of languageOneOf) { 216 for (const l of languageOneOf) {