]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.ts
Merge branch 'release/4.1.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-custom-markup / peertube-custom-tags / video-miniature-markup.component.ts
index c833c56c7b9c5115771862b3bec857890fce283f..cbbacf77c65d6833b14553c6a1424d97b158ced7 100644 (file)
@@ -1,7 +1,10 @@
-import { Component, Input, OnInit } from '@angular/core'
-import { AuthService } from '@app/core'
-import { Video, VideoService } from '../../shared-main'
+import { finalize } from 'rxjs/operators'
+import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
+import { AuthService, Notifier } from '@app/core'
+import { FindInBulkService } from '@app/shared/shared-search'
+import { Video } from '../../shared-main'
 import { MiniatureDisplayOptions } from '../../shared-video-miniature'
+import { CustomMarkupComponent } from './shared'
 
 /*
  * Markup component that creates a video miniature only
@@ -12,10 +15,12 @@ import { MiniatureDisplayOptions } from '../../shared-video-miniature'
   templateUrl: 'video-miniature-markup.component.html',
   styleUrls: [ 'video-miniature-markup.component.scss' ]
 })
-export class VideoMiniatureMarkupComponent implements OnInit {
+export class VideoMiniatureMarkupComponent implements CustomMarkupComponent, OnInit {
   @Input() uuid: string
+  @Input() onlyDisplayTitle: boolean
+  @Input() video: Video
 
-  video: Video
+  @Output() loaded = new EventEmitter<boolean>()
 
   displayOptions: MiniatureDisplayOptions = {
     date: true,
@@ -30,7 +35,8 @@ export class VideoMiniatureMarkupComponent implements OnInit {
 
   constructor (
     private auth: AuthService,
-    private videoService: VideoService
+    private findInBulk: FindInBulkService,
+    private notifier: Notifier
   ) { }
 
   getUser () {
@@ -38,7 +44,20 @@ export class VideoMiniatureMarkupComponent implements OnInit {
   }
 
   ngOnInit () {
-    this.videoService.getVideo({ videoId: this.uuid })
-      .subscribe(video => this.video = video)
+    if (this.onlyDisplayTitle) {
+      for (const key of Object.keys(this.displayOptions)) {
+        this.displayOptions[key] = false
+      }
+    }
+
+    if (this.video) return
+
+    this.findInBulk.getVideo(this.uuid)
+      .pipe(finalize(() => this.loaded.emit(true)))
+      .subscribe({
+        next: video => this.video = video,
+
+        error: err => this.notifier.error($localize`Error in video miniature component: ${err.message}`)
+      })
   }
 }