]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts
Refactor - improve offset content handling with fixed sub-menu and broadcast-message
[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 { I18n } from '@ngx-translate/i18n-polyfill'
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 (
29 private screenService: ScreenService,
30 private i18n: I18n
31 ) {
32 this.addToWatchLaterText = this.i18n('Add to watch later')
33 this.addedToWatchLaterText = this.i18n('Remove from watch later')
34 }
35
36 getImageUrl () {
37 if (!this.video) return ''
38
39 if (this.screenService.isInMobileView()) {
40 return this.video.previewUrl
41 }
42
43 return this.video.thumbnailUrl
44 }
45
46 getProgressPercent () {
47 if (!this.video.userHistory) return 0
48
49 const currentTime = this.video.userHistory.currentTime
50
51 return (currentTime / this.video.duration) * 100
52 }
53
54 getVideoRouterLink () {
55 if (this.videoRouterLink) return this.videoRouterLink
56
57 return [ '/videos/watch', this.video.uuid ]
58 }
59
60 onWatchLaterClick (event: Event) {
61 this.watchLaterClick.emit(this.inWatchLaterPlaylist)
62
63 event.stopPropagation()
64 return false
65 }
66 }