From 2009d38a9116ccabb10c3fae4dec6aa1c9b27d2d Mon Sep 17 00:00:00 2001 From: absidue <48293849+absidue@users.noreply.github.com> Date: Wed, 18 Sep 2024 19:29:42 +0200 Subject: [PATCH 1/2] Update subscription cache when subscribing from the channel page --- .../ChannelDetails/ChannelDetails.vue | 7 +++- .../ft-subscribe-button.js | 2 ++ src/renderer/views/Channel/Channel.js | 32 +++++++++++++++++++ src/renderer/views/Channel/Channel.vue | 1 + 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/renderer/components/ChannelDetails/ChannelDetails.vue b/src/renderer/components/ChannelDetails/ChannelDetails.vue index c6574c40d81c1..296457569d381 100644 --- a/src/renderer/components/ChannelDetails/ChannelDetails.vue +++ b/src/renderer/components/ChannelDetails/ChannelDetails.vue @@ -60,6 +60,7 @@ :channel-id="id" :channel-name="name" :channel-thumbnail="thumbnailUrl" + @subscribed="subscribed" /> @@ -277,7 +278,7 @@ const props = defineProps({ } }) -const emit = defineEmits(['change-tab', 'search']) +const emit = defineEmits(['change-tab', 'search', 'subscribed']) const hideChannelSubscriptions = computed(() => { return store.getters.getHideChannelSubscriptions @@ -298,6 +299,10 @@ const formattedSubCount = computed(() => { return formatNumber(props.subCount) }) +function subscribed() { + emit('subscribed') +} + /** * @param {string} tab */ diff --git a/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js b/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js index 56b158a9ddc14..da395dcb706a3 100644 --- a/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js +++ b/src/renderer/components/ft-subscribe-button/ft-subscribe-button.js @@ -42,6 +42,7 @@ export default defineComponent({ required: false } }, + emits: ['subscribed'], data: function () { return { isProfileDropdownOpen: false, @@ -139,6 +140,7 @@ export default defineComponent({ this.addChannelToProfiles({ channel, profileIds }) showToast(this.$t('Channel.Added channel to your subscriptions')) + this.$emit('subscribed') } if (this.isProfileDropdownEnabled && this.openDropdownOnSubscribe && !this.isProfileDropdownOpen) { diff --git a/src/renderer/views/Channel/Channel.js b/src/renderer/views/Channel/Channel.js index 96730bdcd1543..d0918a99e3904 100644 --- a/src/renderer/views/Channel/Channel.js +++ b/src/renderer/views/Channel/Channel.js @@ -1991,6 +1991,38 @@ export default defineComponent({ }) }, + handleSubscription: function () { + // We can't cache the shorts data as YouTube doesn't return published dates on the shorts channel tab + + // Create copies of the arrays so that we only cache the first page + // If we use the same array, the store will get angry at us for modifying it outside of the store + // when the user clicks load more + + if (this.latestVideos.length > 0 && this.videoSortBy === 'newest') { + this.updateSubscriptionVideosCacheByChannel({ + channelId: this.id, + videos: [...this.latestVideos] + }) + } + + if (this.latestLive.length > 0 && this.liveSortBy === 'newest') { + this.updateSubscriptionLiveCacheByChannel({ + channelId: this.id, + videos: [...this.latestLive] + }) + } + + if (this.latestCommunityPosts.length > 0) { + this.latestCommunityPosts.forEach(post => { + post.authorId = this.id + }) + this.updateSubscriptionPostsCacheByChannel({ + channelId: this.id, + posts: [...this.latestCommunityPosts] + }) + } + }, + getIconForSortPreference: (s) => getIconForSortPreference(s), ...mapActions([ diff --git a/src/renderer/views/Channel/Channel.vue b/src/renderer/views/Channel/Channel.vue index c173205a6d50d..dc2099bf77b44 100644 --- a/src/renderer/views/Channel/Channel.vue +++ b/src/renderer/views/Channel/Channel.vue @@ -20,6 +20,7 @@ class="card channelDetails" @change-tab="changeTab" @search="newSearch" + @subscribed="handleSubscription" /> Date: Thu, 19 Sep 2024 19:20:54 +0200 Subject: [PATCH 2/2] Remove length checks to support missing channel tabs --- src/renderer/views/Channel/Channel.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/renderer/views/Channel/Channel.js b/src/renderer/views/Channel/Channel.js index d0918a99e3904..d384e55adebe0 100644 --- a/src/renderer/views/Channel/Channel.js +++ b/src/renderer/views/Channel/Channel.js @@ -1998,29 +1998,27 @@ export default defineComponent({ // If we use the same array, the store will get angry at us for modifying it outside of the store // when the user clicks load more - if (this.latestVideos.length > 0 && this.videoSortBy === 'newest') { + if (this.videoSortBy === 'newest') { this.updateSubscriptionVideosCacheByChannel({ channelId: this.id, videos: [...this.latestVideos] }) } - if (this.latestLive.length > 0 && this.liveSortBy === 'newest') { + if (this.liveSortBy === 'newest') { this.updateSubscriptionLiveCacheByChannel({ channelId: this.id, videos: [...this.latestLive] }) } - if (this.latestCommunityPosts.length > 0) { - this.latestCommunityPosts.forEach(post => { - post.authorId = this.id - }) - this.updateSubscriptionPostsCacheByChannel({ - channelId: this.id, - posts: [...this.latestCommunityPosts] - }) - } + this.latestCommunityPosts.forEach(post => { + post.authorId = this.id + }) + this.updateSubscriptionPostsCacheByChannel({ + channelId: this.id, + posts: [...this.latestCommunityPosts] + }) }, getIconForSortPreference: (s) => getIconForSortPreference(s),