Skip to content

Commit

Permalink
Update subscription cache when subscribing from the channel page (#5717)
Browse files Browse the repository at this point in the history
* Update subscription cache when subscribing from the channel page

* Remove length checks to support missing channel tabs
  • Loading branch information
absidue authored Sep 20, 2024
1 parent 9f9f3f2 commit 841e301
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/renderer/components/ChannelDetails/ChannelDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
:channel-id="id"
:channel-name="name"
:channel-thumbnail="thumbnailUrl"
@subscribed="subscribed"
/>
</div>
</div>
Expand Down Expand Up @@ -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
Expand All @@ -298,6 +299,10 @@ const formattedSubCount = computed(() => {
return formatNumber(props.subCount)
})
function subscribed() {
emit('subscribed')
}
/**
* @param {string} tab
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default defineComponent({
required: false
}
},
emits: ['subscribed'],
data: function () {
return {
isProfileDropdownOpen: false,
Expand Down Expand Up @@ -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) {
Expand Down
30 changes: 30 additions & 0 deletions src/renderer/views/Channel/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1991,6 +1991,36 @@ 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.videoSortBy === 'newest') {
this.updateSubscriptionVideosCacheByChannel({
channelId: this.id,
videos: [...this.latestVideos]
})
}

if (this.liveSortBy === 'newest') {
this.updateSubscriptionLiveCacheByChannel({
channelId: this.id,
videos: [...this.latestLive]
})
}

this.latestCommunityPosts.forEach(post => {
post.authorId = this.id
})
this.updateSubscriptionPostsCacheByChannel({
channelId: this.id,
posts: [...this.latestCommunityPosts]
})
},

getIconForSortPreference: (s) => getIconForSortPreference(s),

...mapActions([
Expand Down
1 change: 1 addition & 0 deletions src/renderer/views/Channel/Channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class="card channelDetails"
@change-tab="changeTab"
@search="newSearch"
@subscribed="handleSubscription"
/>
<ft-card
v-if="!isLoading && !errorMessage && (isFamilyFriendly || !showFamilyFriendlyOnly)"
Expand Down

0 comments on commit 841e301

Please sign in to comment.