FreeTube/src/renderer/components/watch-video-info/watch-video-info.js

257 lines
6.7 KiB
JavaScript
Raw Normal View History

2020-02-16 19:30:00 +01:00
import Vue from 'vue'
2020-08-05 05:44:34 +02:00
import { mapActions } from 'vuex'
2020-02-16 19:30:00 +01:00
import FtCard from '../ft-card/ft-card.vue'
import FtButton from '../ft-button/ft-button.vue'
import FtListDropdown from '../ft-list-dropdown/ft-list-dropdown.vue'
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
2020-06-06 05:15:44 +02:00
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
2020-06-17 14:15:36 +02:00
import FtShareButton from '../ft-share-button/ft-share-button.vue'
// import { shell } from 'electron'
2020-02-16 19:30:00 +01:00
export default Vue.extend({
name: 'WatchVideoInfo',
components: {
'ft-card': FtCard,
'ft-button': FtButton,
'ft-list-dropdown': FtListDropdown,
2020-06-06 05:15:44 +02:00
'ft-flex-box': FtFlexBox,
2020-06-17 14:15:36 +02:00
'ft-icon-button': FtIconButton,
'ft-share-button': FtShareButton
2020-02-16 19:30:00 +01:00
},
props: {
id: {
type: String,
required: true
},
title: {
type: String,
required: true
},
channelId: {
type: String,
required: true
},
channelName: {
type: String,
required: true
},
channelThumbnail: {
type: String,
required: true
},
published: {
type: Number,
required: true
},
2020-02-16 19:30:00 +01:00
viewCount: {
type: Number,
required: true
},
subscriptionCountText: {
type: String,
required: true
},
likeCount: {
type: Number,
default: 0
2020-02-16 19:30:00 +01:00
},
dislikeCount: {
type: Number,
default: 0
2020-09-11 05:48:06 +02:00
},
2020-09-12 05:20:26 +02:00
getTimestamp: {
type: Function,
required: true
},
isUpcoming: {
type: Boolean,
required: true
2020-02-16 19:30:00 +01:00
}
},
data: function () {
return {
formatTypeLabel: 'VIDEO FORMATS',
formatTypeValues: [
'dash',
'legacy',
'audio'
2020-02-16 19:30:00 +01:00
]
}
},
computed: {
invidiousInstance: function () {
return this.$store.getters.getInvidiousInstance
},
usingElectron: function () {
return this.$store.getters.getUsingElectron
},
profileList: function () {
return this.$store.getters.getProfileList
},
activeProfile: function () {
return this.$store.getters.getActiveProfile
},
formatTypeNames: function () {
return [
this.$t('Change Format.Use Dash Formats').toUpperCase(),
this.$t('Change Format.Use Legacy Formats').toUpperCase(),
this.$t('Change Format.Use Audio Formats').toUpperCase()
]
},
2020-02-16 19:30:00 +01:00
totalLikeCount: function () {
if (this.hideVideoLikesAndDislikes) {
return null
}
2020-02-16 19:30:00 +01:00
return this.likeCount + this.dislikeCount
},
likePercentageRatio: function () {
if (this.hideVideoLikesAndDislikes) {
return null
}
2020-02-16 19:30:00 +01:00
return parseInt(this.likeCount / this.totalLikeCount * 100)
},
parsedViewCount: function () {
if (this.hideVideoViews) {
return null
}
return this.viewCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',') + ` ${this.$t('Video.Views').toLowerCase()}`
2020-02-16 19:30:00 +01:00
},
isSubscribed: function () {
const subIndex = this.profileList[this.activeProfile].subscriptions.findIndex((channel) => {
return channel.id === this.channelId
})
if (subIndex === -1) {
return false
} else {
return true
}
},
2020-02-16 19:30:00 +01:00
subscribedText: function () {
if (this.isSubscribed) {
return `${this.$t('Channel.Unsubscribe').toUpperCase()} ${this.subscriptionCountText}`
} else {
return `${this.$t('Channel.Subscribe').toUpperCase()} ${this.subscriptionCountText}`
}
},
dateString() {
const date = new Date(this.published)
const dateSplit = date.toDateString().split(' ')
const localeDateString = `Video.Published.${dateSplit[1]}`
return `${this.$t(localeDateString)} ${dateSplit[2]}, ${dateSplit[3]}`
},
hideVideoLikesAndDislikes: function () {
return this.$store.getters.getHideVideoLikesAndDislikes
},
hideVideoViews: function () {
return this.$store.getters.getHideVideoViews
2020-02-16 19:30:00 +01:00
}
},
methods: {
goToChannel: function () {
this.$router.push({ path: `/channel/${this.channelId}` })
2020-02-16 19:30:00 +01:00
},
handleSubscription: function () {
const currentProfile = JSON.parse(JSON.stringify(this.profileList[this.activeProfile]))
const primaryProfile = JSON.parse(JSON.stringify(this.profileList[0]))
if (this.isSubscribed) {
currentProfile.subscriptions = currentProfile.subscriptions.filter((channel) => {
return channel.id !== this.channelId
})
this.updateProfile(currentProfile)
this.showToast({
2020-09-16 14:51:24 +02:00
message: this.$t('Channel.Channel has been removed from your subscriptions')
})
if (this.activeProfile === 0) {
// Check if a subscription exists in a different profile.
// Remove from there as well.
let duplicateSubscriptions = 0
this.profileList.forEach((profile) => {
if (profile._id === 'allChannels') {
return
}
const parsedProfile = JSON.parse(JSON.stringify(profile))
const index = parsedProfile.subscriptions.findIndex((channel) => {
return channel.id === this.channelId
})
if (index !== -1) {
duplicateSubscriptions++
parsedProfile.subscriptions = parsedProfile.subscriptions.filter((x) => {
return x.id !== this.channelId
})
this.updateProfile(parsedProfile)
}
})
if (duplicateSubscriptions > 0) {
2020-09-16 14:51:24 +02:00
const message = this.$t('Channel.Removed subscription from $ other channel(s)')
this.showToast({
2020-09-16 14:51:24 +02:00
message: message.replace('$', duplicateSubscriptions)
})
}
}
} else {
const subscription = {
id: this.channelId,
name: this.channelName,
thumbnail: this.channelThumbnail
}
currentProfile.subscriptions.push(subscription)
this.updateProfile(currentProfile)
this.showToast({
2020-09-16 14:51:24 +02:00
message: this.$t('Channel.Added channel to your subscriptions')
})
if (this.activeProfile !== 0) {
const index = primaryProfile.subscriptions.findIndex((channel) => {
return channel.id === this.channelId
})
if (index === -1) {
primaryProfile.subscriptions.push(subscription)
this.updateProfile(primaryProfile)
}
}
}
2020-02-16 19:30:00 +01:00
},
handleFormatChange: function (format) {
switch (format) {
case 'dash':
this.$parent.enableDashFormat()
break
case 'legacy':
this.$parent.enableLegacyFormat()
break
case 'audio':
this.$parent.enableAudioFormat()
break
}
2020-08-05 05:44:34 +02:00
},
...mapActions([
'showToast',
'updateProfile'
2020-08-05 05:44:34 +02:00
])
2020-02-16 19:30:00 +01:00
}
})