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 = {
46 userRating: UserVideoRateType
49 private screenService: ScreenService,
50 private redirectService: RedirectService
54 // Hide the tooltips for unlogged users in mobile view, this adds confusion with the popover
55 if (this.isUserLoggedIn || !this.screenService.isInMobileView()) {
56 this.tooltipSupport = $localize`Support options for this video`
57 this.tooltipSaveToPlaylist = $localize`Save to playlist`
62 this.setVideoLikesBarTooltipText()
65 showDownloadModal () {
66 this.videoDownloadModal.show(this.video, this.videoCaptions)
69 isVideoDownloadable () {
70 return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled && !this.video.isLive
74 this.supportModal.show()
78 this.videoShareModal.show(this.currentTime, this.currentPlaylistPosition)
81 onRateUpdated (userRating: UserVideoRateType) {
82 this.userRating = userRating
83 this.setVideoLikesBarTooltipText()
87 this.redirectService.redirectToHomepage()
90 private setVideoLikesBarTooltipText () {
91 this.likesBarTooltipText = `${this.video.likes} likes / ${this.video.dislikes} dislikes`