]>
Commit | Line | Data |
---|---|---|
b7819090 | 1 | import { Component, EventEmitter, Input, Output } from '@angular/core' |
67ed6552 | 2 | import { ScreenService } from '@app/core' |
5c0904fc | 3 | import { VideoState } from '@shared/models' |
67ed6552 | 4 | import { Video } from '../shared-main' |
202f6b6c C |
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 | |
0bdad52f | 14 | |
d4a8e7a6 | 15 | @Input() videoRouterLink: string | any[] |
be27ef3b | 16 | @Input() queryParams: { [ p: string ]: any } |
0bdad52f C |
17 | @Input() videoHref: string |
18 | @Input() videoTarget: string | |
3290f37c | 19 | |
b7819090 C |
20 | @Input() displayWatchLaterPlaylist: boolean |
21 | @Input() inWatchLaterPlaylist: boolean | |
29128b2f | 22 | |
b7819090 C |
23 | @Output() watchLaterClick = new EventEmitter<boolean>() |
24 | ||
25 | addToWatchLaterText: string | |
26 | addedToWatchLaterText: string | |
29128b2f | 27 | |
66357162 C |
28 | constructor (private screenService: ScreenService) { |
29 | this.addToWatchLaterText = $localize`Add to watch later` | |
30 | this.addedToWatchLaterText = $localize`Remove from watch later` | |
e2f01c47 | 31 | } |
bbe0f064 | 32 | |
5c0904fc | 33 | isLiveEnded () { |
91f884d1 C |
34 | if (!this.video.state) return |
35 | ||
5c0904fc C |
36 | return this.video.state.id === VideoState.LIVE_ENDED |
37 | } | |
38 | ||
3290f37c C |
39 | getImageUrl () { |
40 | if (!this.video) return '' | |
41 | ||
bbe0f064 | 42 | if (this.screenService.isInMobileView()) { |
3290f37c C |
43 | return this.video.previewUrl |
44 | } | |
45 | ||
46 | return this.video.thumbnailUrl | |
47 | } | |
6e46de09 C |
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 | } | |
e2f01c47 C |
56 | |
57 | getVideoRouterLink () { | |
0bdad52f | 58 | if (this.videoRouterLink) return this.videoRouterLink |
e2f01c47 | 59 | |
d4a8e7a6 | 60 | return Video.buildWatchUrl(this.video) |
e2f01c47 | 61 | } |
29128b2f | 62 | |
b7819090 C |
63 | onWatchLaterClick (event: Event) { |
64 | this.watchLaterClick.emit(this.inWatchLaterPlaylist) | |
29128b2f | 65 | |
b7819090 C |
66 | event.stopPropagation() |
67 | return false | |
29128b2f | 68 | } |
202f6b6c | 69 | } |