]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
Skip videos count on client if we don't use it
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-video-channels / account-video-channels.component.ts
index ee3b5f8e4b6cc3dfe878868312256f5cbda6b78c..5572064c1c95c9e96cde71311cecd5c569c4b704 100644 (file)
@@ -4,13 +4,14 @@ import { Account } from '@app/shared/account/account.model'
 import { AccountService } from '@app/shared/account/account.service'
 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
 import { concatMap, map, switchMap, tap } from 'rxjs/operators'
-import { from, Subscription } from 'rxjs'
+import { from, Subject, Subscription } from 'rxjs'
 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
 import { Video } from '@app/shared/video/video.model'
 import { AuthService } from '@app/core'
 import { VideoService } from '@app/shared/video/video.service'
 import { VideoSortField } from '@app/shared/video/sort-field.type'
 import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model'
+import { ScreenService } from '@app/shared/misc/screen.service'
 
 @Component({
   selector: 'my-account-video-channels',
@@ -24,15 +25,19 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
 
   channelPagination: ComponentPagination = {
     currentPage: 1,
-    itemsPerPage: 2
+    itemsPerPage: 2,
+    totalItems: null
   }
 
   videosPagination: ComponentPagination = {
     currentPage: 1,
-    itemsPerPage: 12
+    itemsPerPage: 12,
+    totalItems: null
   }
   videosSort: VideoSortField = '-publishedAt'
 
+  onChannelDataSubject = new Subject<any>()
+
   private accountSub: Subscription
 
   constructor (
@@ -40,7 +45,8 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
     private authService: AuthService,
     private accountService: AccountService,
     private videoChannelService: VideoChannelService,
-    private videoService: VideoService
+    private videoService: VideoService,
+    private screenService: ScreenService
   ) { }
 
   get user () {
@@ -68,18 +74,23 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
         switchMap(res => from(res.data)),
         concatMap(videoChannel => {
           return this.videoService.getVideoChannelVideos(videoChannel, this.videosPagination, this.videosSort)
-            .pipe(map(data => ({ videoChannel, videos: data.videos })))
+            .pipe(map(data => ({ videoChannel, videos: data.data })))
         })
       )
       .subscribe(({ videoChannel, videos }) => {
         this.videoChannels.push(videoChannel)
 
         this.videos[videoChannel.id] = videos
+
+        this.onChannelDataSubject.next([ videoChannel ])
       })
   }
 
   getVideosOf (videoChannel: VideoChannel) {
-    return this.videos[ videoChannel.id ] || []
+    const numberOfVideos = this.screenService.getNumberOfAvailableMiniatures()
+
+    // 2 rows
+    return this.videos[ videoChannel.id ].slice(0, numberOfVideos * 2)
   }
 
   onNearOfBottom () {
@@ -89,4 +100,8 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
 
     this.loadMoreChannels()
   }
+
+  getVideoChannelLink (videoChannel: VideoChannel) {
+    return [ '/video-channels', videoChannel.nameWithHost ]
+  }
 }