X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fvideo%2Fabstract-video-list.ts;h=c2fe6f75484352a871ba3608a59e6359871e88b1;hb=e612209767ebe1deb0af7688c96b7f979bb52b44;hp=3e3583a70c049c1311dd5b8d25328e9edb31c51a;hpb=9d45db2919862640ad550c5326fb21ddc08d6d59;p=oweals%2Fpeertube.git diff --git a/client/src/app/shared/video/abstract-video-list.ts b/client/src/app/shared/video/abstract-video-list.ts index 3e3583a70..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' import { ActivatedRoute, Router } from '@angular/router' import { fromEvent, Observable, of, Subject, Subscription } from 'rxjs' import { AuthService } from '../../core/auth' -import { ComponentPagination } from '../rest/component-pagination.model' +import { ComponentPaginationLight } from '../rest/component-pagination.model' import { VideoSortField } from './sort-field.type' import { Video } from './video.model' import { ScreenService } from '@app/shared/misc/screen.service' @@ -13,7 +13,7 @@ import { Notifier, ServerService } from '@app/core' import { DisableForReuseHook } from '@app/core/routing/disable-for-reuse-hook' import { I18n } from '@ngx-translate/i18n-polyfill' import { isLastMonth, isLastWeek, isToday, isYesterday } from '@shared/core-utils/miscs/date' -import { ResultList, ServerConfig } from '@shared/models' +import { ServerConfig } from '@shared/models' enum GroupDate { UNKNOWN = 0, @@ -25,10 +25,9 @@ enum GroupDate { } export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableForReuseHook { - pagination: ComponentPagination = { + pagination: ComponentPaginationLight = { currentPage: 1, - itemsPerPage: 25, - totalItems: null + itemsPerPage: 25 } sort: VideoSortField = '-publishedAt' @@ -47,6 +46,7 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor groupByDate = false videos: Video[] = [] + hasDoneFirstQuery = false disabled = false displayOptions: MiniatureDisplayOptions = { @@ -59,6 +59,12 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor blacklistInfo: false } + actions: { + routerLink: string + iconName: string + label: string + }[] = [] + onDataSubject = new Subject() protected serverConfig: ServerConfig @@ -78,7 +84,9 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor private groupedDateLabels: { [id in GroupDate]: string } private groupedDates: { [id: number]: GroupDate } = {} - abstract getVideosObservable (page: number): Observable> + private lastQueryLength: number + + abstract getVideosObservable (page: number): Observable<{ data: Video[] }> abstract generateSyndicationList (): void @@ -136,8 +144,8 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor onNearOfBottom () { if (this.disabled) return - // Last page - if (this.pagination.totalItems <= (this.pagination.currentPage * this.pagination.itemsPerPage)) return + // No more results + if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return this.pagination.currentPage += 1 @@ -148,8 +156,10 @@ export abstract class AbstractVideoList implements OnInit, OnDestroy, DisableFor loadMoreVideos (reset = false) { this.getVideosObservable(this.pagination.currentPage).subscribe( - ({ data, total }) => { - this.pagination.totalItems = total + ({ data }) => { + this.hasDoneFirstQuery = true + this.lastQueryLength = data.length + if (reset) this.videos = [] this.videos = this.videos.concat(data)