Skip to content

Update subscription cache when subscribing from the channel page #5717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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