]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts
Fix missing link orange
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channel-videos / video-channel-videos.component.ts
index 28c591039fa59ef37dd4c76fed690fb9cc6780b0..43fce475d2422709c330e26ac38d1da6263090cf 100644 (file)
@@ -1,80 +1,82 @@
+import { Subscription } from 'rxjs'
+import { first } from 'rxjs/operators'
 import { Component, OnDestroy, OnInit } from '@angular/core'
-import { ActivatedRoute, Router } from '@angular/router'
-import { Location } from '@angular/common'
-import { immutableAssign } from '@app/shared/misc/utils'
-import { NotificationsService } from 'angular2-notifications'
-import { AuthService } from '../../core/auth'
-import { ConfirmService } from '../../core/confirm'
-import { AbstractVideoList } from '../../shared/video/abstract-video-list'
-import { VideoService } from '../../shared/video/video.service'
-import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
-import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
-import { tap } from 'rxjs/operators'
-import { I18n } from '@ngx-translate/i18n-polyfill'
+import { ComponentPaginationLight, DisableForReuseHook, ScreenService } from '@app/core'
+import { VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
+import { MiniatureDisplayOptions, VideoFilters } from '@app/shared/shared-video-miniature'
+import { VideoSortField } from '@shared/models/videos'
 
 @Component({
   selector: 'my-video-channel-videos',
-  templateUrl: '../../shared/video/abstract-video-list.html',
-  styleUrls: [
-    '../../shared/video/abstract-video-list.scss',
-    './video-channel-videos.component.scss'
-  ]
+  templateUrl: './video-channel-videos.component.html'
 })
-export class VideoChannelVideosComponent extends AbstractVideoList implements OnInit, OnDestroy {
-  titlePage: string
-  marginContent = false // Disable margin
-  currentRoute = '/video-channel/videos'
-  loadOnInit = false
+export class VideoChannelVideosComponent implements OnInit, OnDestroy, DisableForReuseHook {
+  getVideosObservableFunction = this.getVideosObservable.bind(this)
+  getSyndicationItemsFunction = this.getSyndicationItems.bind(this)
 
-  private videoChannel: VideoChannel
+  title = $localize`Videos`
+  defaultSort = '-publishedAt' as VideoSortField
+
+  displayOptions: MiniatureDisplayOptions = {
+    date: true,
+    views: true,
+    by: false,
+    avatar: false,
+    privacyLabel: true,
+    privacyText: false,
+    state: false,
+    blacklistInfo: false
+  }
+
+  videoChannel: VideoChannel
+  disabled = false
+
+  private videoChannelSub: Subscription
 
   constructor (
-    protected router: Router,
-    protected route: ActivatedRoute,
-    protected authService: AuthService,
-    protected notificationsService: NotificationsService,
-    protected confirmService: ConfirmService,
-    protected location: Location,
-    protected i18n: I18n,
+    private screenService: ScreenService,
     private videoChannelService: VideoChannelService,
     private videoService: VideoService
   ) {
-    super()
-
-    this.titlePage = this.i18n('Published videos')
   }
 
   ngOnInit () {
-    super.ngOnInit()
-
     // Parent get the video channel for us
-    this.videoChannelService.videoChannelLoaded
+    this.videoChannelService.videoChannelLoaded.pipe(first())
       .subscribe(videoChannel => {
         this.videoChannel = videoChannel
-        this.currentRoute = '/video-channel/' + this.videoChannel.uuid + '/videos'
-
-        this.loadMoreVideos(this.pagination.currentPage)
-        this.generateSyndicationList()
       })
   }
 
   ngOnDestroy () {
-    super.ngOnDestroy()
+    if (this.videoChannelSub) this.videoChannelSub.unsubscribe()
   }
 
-  getVideosObservable (page: number) {
-    const newPagination = immutableAssign(this.pagination, { currentPage: page })
+  getVideosObservable (pagination: ComponentPaginationLight, filters: VideoFilters) {
+    const params = {
+      ...filters.toVideosAPIObject(),
+
+      videoPagination: pagination,
+      videoChannel: this.videoChannel,
+      skipCount: true
+    }
+
+    return this.videoService.getVideoChannelVideos(params)
+  }
+
+  getSyndicationItems () {
+    return this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
+  }
+
+  displayAsRow () {
+    return this.screenService.isInMobileView()
+  }
 
-    return this.videoService
-               .getVideoChannelVideos(this.videoChannel, newPagination, this.sort)
-               .pipe(
-                 tap(({ totalVideos }) => {
-                   this.titlePage = this.i18n('Published {{totalVideos}} videos', { totalVideos })
-                 })
-               )
+  disableForReuse () {
+    this.disabled = true
   }
 
-  generateSyndicationList () {
-    this.syndicationItems = this.videoService.getVideoChannelFeedUrls(this.videoChannel.id)
+  enabledForReuse () {
+    this.disabled = false
   }
 }