diff options
Diffstat (limited to 'client/src/app/shared/video/abstract-video-list.ts')
-rw-r--r-- | client/src/app/shared/video/abstract-video-list.ts | 24 |
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' | |||
3 | import { ActivatedRoute, Router } from '@angular/router' | 3 | import { ActivatedRoute, Router } from '@angular/router' |
4 | import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs' | 4 | import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs' |
5 | import { AuthService } from '../../core/auth' | 5 | import { AuthService } from '../../core/auth' |
6 | import { ComponentPagination } from '../rest/component-pagination.model' | 6 | import { ComponentPaginationLight } from '../rest/component-pagination.model' |
7 | import { VideoSortField } from './sort-field.type' | 7 | import { VideoSortField } from './sort-field.type' |
8 | import { Video } from './video.model' | 8 | import { Video } from './video.model' |
9 | import { ScreenService } from '@app/shared/misc/screen.service' | 9 | import { ScreenService } from '@app/shared/misc/screen.service' |
@@ -13,7 +13,7 @@ import { Notifier, ServerService } from '@app/core' | |||
13 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' | 13 | import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' |
14 | import { I18n } from '@ngx-translate/i18n-polyfill' | 14 | import { I18n } from '@ngx-translate/i18n-polyfill' |
15 | import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' | 15 | import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' |
16 | import { ResultList, ServerConfig } from '@shared/models' | 16 | import { ServerConfig } from '@shared/models' |
17 | 17 | ||
18 | enum GroupDate { | 18 | enum GroupDate { |
19 | UNKNOWN = 0, | 19 | UNKNOWN = 0, |
@@ -25,10 +25,9 @@ enum GroupDate { | |||
25 | } | 25 | } |
26 | 26 | ||
27 | export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableForReuseHook { | 27 | export 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 | ||