]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts
bdede17a3d448bc13651b28cdbd6fc1a9b95754c
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-thumbnail / video-thumbnail.component.ts
1 import { Component, EventEmitter, Input, Output } from '@angular/core'
2 import { ScreenService } from '@app/core'
3 import { VideoState } from '@shared/models'
4 import { Video } from '../shared-main'
5
6 @Component({
7 selector: 'my-video-thumbnail',
8 styleUrls: [ './video-thumbnail.component.scss' ],
9 templateUrl: './video-thumbnail.component.html'
10 })
11 export class VideoThumbnailComponent {
12 @Input() video: Video
13 @Input() nsfw = false
14
15 @Input() videoRouterLink: any[]
16 @Input() queryParams: { [ p: string ]: any }
17 @Input() videoHref: string
18 @Input() videoTarget: string
19
20 @Input() displayWatchLaterPlaylist: boolean
21 @Input() inWatchLaterPlaylist: boolean
22
23 @Output() watchLaterClick = new EventEmitter<boolean>()
24
25 addToWatchLaterText: string
26 addedToWatchLaterText: string
27
28 constructor (private screenService: ScreenService) {
29 this.addToWatchLaterText = $localize`Add to watch later`
30 this.addedToWatchLaterText = $localize`Remove from watch later`
31 }
32
33 isLiveEnded () {
34 if (!this.video.state) return
35
36 return this.video.state.id === VideoState.LIVE_ENDED
37 }
38
39 getImageUrl () {
40 if (!this.video) return ''
41
42 if (this.screenService.isInMobileView()) {
43 return this.video.previewUrl
44 }
45
46 return this.video.thumbnailUrl
47 }
48
49 getProgressPercent () {
50 if (!this.video.userHistory) return 0
51
52 const currentTime = this.video.userHistory.currentTime
53
54 return (currentTime / this.video.duration) * 100
55 }
56
57 getVideoRouterLink () {
58 if (this.videoRouterLink) return this.videoRouterLink
59
60 return [ '/videos/watch', this.video.uuid ]
61 }
62
63 onWatchLaterClick (event: Event) {
64 this.watchLaterClick.emit(this.inWatchLaterPlaylist)
65
66 event.stopPropagation()
67 return false
68 }
69 }