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