]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-custom-markup/peertube-custom-tags/video-miniature-markup.component.ts
Update angular
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-custom-markup / peertube-custom-tags / video-miniature-markup.component.ts
CommitLineData
8b61dcaf 1import { finalize } from 'rxjs/operators'
647c2b7d 2import { ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
8b61dcaf 3import { AuthService, Notifier } from '@app/core'
9df52d66
C
4import { FindInBulkService } from '@app/shared/shared-search'
5import { Video } from '../../shared-main'
8ee25e17 6import { MiniatureDisplayOptions } from '../../shared-video-miniature'
0ca454e3 7import { CustomMarkupComponent } from './shared'
2539932e
C
8
9/*
10 * Markup component that creates a video miniature only
11*/
12
13@Component({
14 selector: 'my-video-miniature-markup',
15 templateUrl: 'video-miniature-markup.component.html',
bc48e33b
C
16 styleUrls: [ 'video-miniature-markup.component.scss' ],
17 changeDetection: ChangeDetectionStrategy.OnPush
2539932e 18})
0ca454e3 19export class VideoMiniatureMarkupComponent implements CustomMarkupComponent, OnInit {
2539932e 20 @Input() uuid: string
9105634f 21 @Input() onlyDisplayTitle: boolean
e9609325 22 @Input() video: Video
2539932e 23
0ca454e3
C
24 @Output() loaded = new EventEmitter<boolean>()
25
2539932e
C
26 displayOptions: MiniatureDisplayOptions = {
27 date: true,
28 views: true,
29 by: true,
30 avatar: false,
31 privacyLabel: false,
32 privacyText: false,
33 state: false,
34 blacklistInfo: false
35 }
36
37 constructor (
38 private auth: AuthService,
3da38d6e 39 private findInBulk: FindInBulkService,
647c2b7d
C
40 private notifier: Notifier,
41 private cd: ChangeDetectorRef
2539932e
C
42 ) { }
43
44 getUser () {
45 return this.auth.getUser()
46 }
47
48 ngOnInit () {
9105634f
C
49 if (this.onlyDisplayTitle) {
50 for (const key of Object.keys(this.displayOptions)) {
51 this.displayOptions[key] = false
52 }
53 }
54
e9609325
C
55 if (this.video) return
56
3da38d6e 57 this.findInBulk.getVideo(this.uuid)
8b61dcaf 58 .pipe(finalize(() => this.loaded.emit(true)))
1378c0d3 59 .subscribe({
647c2b7d
C
60 next: video => {
61 this.video = video
62 this.cd.markForCheck()
63 },
0ca454e3 64
1378c0d3
C
65 error: err => this.notifier.error($localize`Error in video miniature component: ${err.message}`)
66 })
2539932e
C
67 }
68}