PeerTube/client/src/app/shared/shared-thumbnail/video-thumbnail.component.ts

70 lines
1.7 KiB
TypeScript
Raw Normal View History

2020-01-03 15:01:17 +01:00
import { Component, EventEmitter, Input, Output } from '@angular/core'
2020-06-23 14:10:17 +02:00
import { ScreenService } from '@app/core'
2020-11-13 14:36:30 +01:00
import { VideoState } from '@shared/models'
2020-06-23 14:10:17 +02:00
import { Video } from '../shared-main'
2017-12-01 18:56:26 +01:00
@Component({
selector: 'my-video-thumbnail',
styleUrls: [ './video-thumbnail.component.scss' ],
templateUrl: './video-thumbnail.component.html'
})
export class VideoThumbnailComponent {
@Input() video: Video
@Input() nsfw = false
@Input() videoRouterLink: string | any[]
2020-02-10 14:25:38 +01:00
@Input() queryParams: { [ p: string ]: any }
@Input() videoHref: string
@Input() videoTarget: string
2020-01-03 15:01:17 +01:00
@Input() displayWatchLaterPlaylist: boolean
@Input() inWatchLaterPlaylist: boolean
2020-01-03 15:01:17 +01:00
@Output() watchLaterClick = new EventEmitter<boolean>()
addToWatchLaterText: string
addedToWatchLaterText: string
constructor (private screenService: ScreenService) {
this.addToWatchLaterText = $localize`Add to watch later`
this.addedToWatchLaterText = $localize`Remove from watch later`
2019-03-13 14:18:58 +01:00
}
2020-11-13 14:36:30 +01:00
isLiveEnded () {
2020-12-17 13:46:52 +01:00
if (!this.video.state) return
2020-11-13 14:36:30 +01:00
return this.video.state.id === VideoState.LIVE_ENDED
}
getImageUrl () {
if (!this.video) return ''
if (this.screenService.isInMobileView()) {
return this.video.previewUrl
}
return this.video.thumbnailUrl
}
2018-10-05 11:15:06 +02:00
getProgressPercent () {
if (!this.video.userHistory) return 0
const currentTime = this.video.userHistory.currentTime
return (currentTime / this.video.duration) * 100
}
2019-03-13 14:18:58 +01:00
getVideoRouterLink () {
if (this.videoRouterLink) return this.videoRouterLink
2019-03-13 14:18:58 +01:00
return Video.buildWatchUrl(this.video)
2019-03-13 14:18:58 +01:00
}
2020-01-03 15:01:17 +01:00
onWatchLaterClick (event: Event) {
this.watchLaterClick.emit(this.inWatchLaterPlaylist)
2020-01-03 15:01:17 +01:00
event.stopPropagation()
return false
}
2017-12-01 18:56:26 +01:00
}