From ea362ab2957aa36328367245f5b84806ac377795 Mon Sep 17 00:00:00 2001 From: Alhuin Date: Sat, 12 Nov 2022 17:09:58 +0100 Subject: [PATCH 1/5] #1414: Add share button ton Channel view - Update src/renderer/components/ft-share-button to handle Channels - Update english locale entries for 'Share channel' --- .../ft-share-button/ft-share-button.js | 34 ++++++++++++++++++- .../ft-share-button/ft-share-button.vue | 9 +++-- static/locales/en-US.yaml | 1 + static/locales/en_GB.yaml | 1 + 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/ft-share-button/ft-share-button.js b/src/renderer/components/ft-share-button/ft-share-button.js index dbe9084bac159..46d77cf72f030 100644 --- a/src/renderer/components/ft-share-button/ft-share-button.js +++ b/src/renderer/components/ft-share-button/ft-share-button.js @@ -15,6 +15,15 @@ export default Vue.extend({ 'ft-toggle-switch': FtToggleSwitch }, props: { + mediaType: { + /** + * Allows to render the dropdown conditionally + * 'Channel' will exclude embed links + * 'Video' (default) keeps the original behaviour + **/ + type: String, + default: 'Video' + }, id: { type: String, required: true @@ -25,7 +34,7 @@ export default Vue.extend({ }, getTimestamp: { type: Function, - required: true + default: null } }, data: function () { @@ -34,11 +43,22 @@ export default Vue.extend({ } }, computed: { + isChannel: function() { + return this.mediaType === 'Channel' + }, + + isVideo: function() { + return this.mediaType === 'Video' + }, + currentInvidiousInstance: function () { return this.$store.getters.getCurrentInvidiousInstance }, invidiousURL() { + if (this.isChannel) { + return `${this.currentInvidiousInstance}/channel/${this.id}` + } let videoUrl = `${this.currentInvidiousInstance}/watch?v=${this.id}` // `playlistId` can be undefined if (this.playlistId && this.playlistId.length !== 0) { @@ -53,6 +73,9 @@ export default Vue.extend({ }, youtubeURL() { + if (this.isChannel) { + return `https://www.youtube.com/channel/${this.id}` + } let videoUrl = `https://www.youtube.com/watch?v=${this.id}` // `playlistId` can be undefined if (this.playlistId && this.playlistId.length !== 0) { @@ -75,6 +98,12 @@ export default Vue.extend({ return `https://www.youtube-nocookie.com/embed/${this.id}` } }, + mounted() { + // Prevents to instantiate a ft-share-button for a video without a get-timestamp function + if (this.isVideo && !this.getTimestamp) { + console.error('Error in props validation: A Video ft-share-button requires a valid get-timestamp function.') + } + }, methods: { openInvidious() { @@ -122,6 +151,9 @@ export default Vue.extend({ }, getFinalUrl(url) { + if (this.isChannel) { + return url + } if (url.indexOf('?') === -1) { return this.includeTimestamp ? `${url}?t=${this.getTimestamp()}` : url } diff --git a/src/renderer/components/ft-share-button/ft-share-button.vue b/src/renderer/components/ft-share-button/ft-share-button.vue index 6b9da16e030be..a1ea616b9cf2b 100644 --- a/src/renderer/components/ft-share-button/ft-share-button.vue +++ b/src/renderer/components/ft-share-button/ft-share-button.vue @@ -1,14 +1,15 @@