1 import { Component, Input, OnChanges, OnInit, ViewChild } from '@angular/core'
2 import { RedirectService, ScreenService } from '@app/core'
3 import { VideoDetails } from '@app/shared/shared-main'
4 import { VideoShareComponent } from '@app/shared/shared-share-modal'
5 import { SupportModalComponent } from '@app/shared/shared-support-modal'
6 import { VideoActionsDisplayType, VideoDownloadComponent } from '@app/shared/shared-video-miniature'
7 import { VideoPlaylist } from '@app/shared/shared-video-playlist'
8 import { UserVideoRateType, VideoCaption } from '@shared/models/videos'
11 selector: 'my-action-buttons',
12 templateUrl: './action-buttons.component.html',
13 styleUrls: [ './action-buttons.component.scss' ]
15 export class ActionButtonsComponent implements OnInit, OnChanges {
16 @ViewChild('videoShareModal') videoShareModal: VideoShareComponent
17 @ViewChild('supportModal') supportModal: SupportModalComponent
18 @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
20 @Input() video: VideoDetails
21 @Input() videoCaptions: VideoCaption[]
22 @Input() playlist: VideoPlaylist
24 @Input() isUserLoggedIn: boolean
26 @Input() currentTime: number
27 @Input() currentPlaylistPosition: number
29 likesBarTooltipText = ''
32 tooltipSaveToPlaylist = ''
34 videoActionsOptions: VideoActionsDisplayType = {
47 userRating: UserVideoRateType
50 private screenService: ScreenService,
51 private redirectService: RedirectService
55 // Hide the tooltips for unlogged users in mobile view, this adds confusion with the popover
56 if (this.isUserLoggedIn || !this.screenService.isInMobileView()) {
57 this.tooltipSupport = $localize`Support options for this video`
58 this.tooltipSaveToPlaylist = $localize`Save to playlist`
63 this.setVideoLikesBarTooltipText()
66 showDownloadModal () {
67 this.videoDownloadModal.show(this.video, this.videoCaptions)
70 isVideoDownloadable () {
71 return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled && !this.video.isLive
75 this.supportModal.show()
79 this.videoShareModal.show(this.currentTime, this.currentPlaylistPosition)
82 onRateUpdated (userRating: UserVideoRateType) {
83 this.userRating = userRating
84 this.setVideoLikesBarTooltipText()
88 this.redirectService.redirectToHomepage()
91 private setVideoLikesBarTooltipText () {
92 this.likesBarTooltipText = `${this.video.likes} likes / ${this.video.dislikes} dislikes`